Friday, April 13, 2007

Ways of Extending ActionForm

There are two different flavors of Action Form exist.

Action Form as a Java Bean

In this implementation of Action Form developer will have to define a property in Action Form class for each input defined in HTML form. There will also be getter and setter for each of those properties. This concept of having properties and getter and setters for all properties is a concept of Java Bean.

Action Form as a map

Action Form is a mapping between HTML form properties and business object corresponding to that form. The map can be used to trap all parameters passed without defining any of the properties in advance. Each field is just another entry on the Map. This can save developers effort a bit where developer will have to define two methods (public void setvalue(String key, Object value and public Object getValue(String key) instead of getter and setters of each property of the form.


Declaring simple properties in the usual way add up to a lot of work in a larger application.To create conventional JavaBean ActionForm, You need to code a field, a getter, and a setter; A lot of infrastructure just to say get this and set that. It would be faster if we could just declare the Java Bean properties instead to code each one and system takes care of defining getter and setters of those properties. DynaActionForms are designed for the purpose. You could just define an Action Form in struts-config.xml file and declare what all properties it holds and Struts takes care of rest of things. It is actually based on DynaBean component of the Jakarta Commons.

There is one difference in reset method of Action Form in DynaActionForm implementation and Map based or Java Bean based implementation.

In case of DynaActionForm implementation; reset method will set all properties to its initial values which are defined in struts-config.xml while defining Action Form. while in case of other two implementation reset method will set all properties to their default values which depend on type of a property.

Labels: , , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home