Howdy,
Struts newbie here. I'm in the process of evaluating Struts for use in a project and one of the criteria I'm checking out is how to deal with non-text data to and from a form.
For my
test case I coded a fairly simple Money class that represents a currency value (stored internally as an integer value of pennies). This class has a factory method that can construct a Money instance from a parsed text field, and has a toString() method that returns the value formatted as its textual equivalent.
So in my AmountForm (extending ActionForm) I have the following instance variable, setter, and getter for a field with the key "amount":
So far, so good.
But of course, my actions aren't really interested in the text format of the field, but in the Money instance itself. So I changed the getter to:
Figuring that because Money has a toString() method, that all would be well: my actions could obtain the Money instance, and Struts could obtain the text format for displaying on the pages.
Well, that broke things. Strangely enough, the symptom of the above change seems to cause the setter to not be called upon form submission (all seems to go well with he getter itself).
I'm not sure why the symptoms of the failure are as such, but my question hoils down to this:
What
patterns do you use to handle this type of non-textual data in your Struts forms?
Do you create 2 getters: the bean-patterned setter to return the text value, AND a getter to get the Money (or other non-text) class instance? As in:
This seems rather messy to me, and since this is probably a common requirement (use of non-text data), I figured someone must have come up with a better pattern.
Thanks for any input you all might have!
bear