Re: In FormBean can we write other methods than set,get,validate?
Friday, April 8, 2005 09:37 PM
(you forgot "reset()" by the way, in your list of FormBean methods you might want to "override" in your subclass)
Of course you can write any method you want, since it is a Java class (assuming you've actually extended FormBean, rather than just defining a form-bean as a DynaActionForm).
The question is, why do you want to? and how will you call it? and is the FormBean the most appropriate place to put that method?
When first learning Struts, I also started off putting lots of stuff in FormBeans.
But then I learned that usually you are better off doing things in a "prefillAction", rather than in a FormBean subclass itself.
I think it is also a good idea to use DynaActionForms where possible, so you don't have so much of your own code to maintain (especially if you start getting a lot of form-beans as a web application grows in complexity); and then you don't get to write any methods in the form-bean since you are not even writing a Java class for it.... So with a DynaActionForm, anything you want to do HAS to go into a "prefillAction".