Struts 1.2 mandated that every HTML form in the JSPs have an associated ActionForm. Struts 1.1 changed all that with the introduction of
DynaActionForm – dynamic ActionForm as the name suggests. DynaActionForm is defined in the struts-config.xml as a form-bean. A sample
DynaActionForm is shown below Sample DynaActionForm
1 2 3 4 5 6 7 8 | <form-bean name="bean" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="id" type="java.lang.String" /> <form-property name="name" type="java.lang.String" /> <form-property name="address" type="java.lang.String" /> <form-property name="email" type="java.lang.String" /> <form-property name="doj" type="java.lang.String" /> <form-property name="age" type="java.lang.String" /> </form-bean> |
There are two things
- For a DynaActionForm, the type attribute of the form-bean is always
org.apache.struts.action.DynaActionForm
. - A regular ActionForm is developed in Java and declared in the
struts-config.xml
. The JavaBeans properties of a regular ActionForm are created by first defining the instance variable and then adding a getter and setter for that instance variable. A DynaActionForm has no associated Java class. Its JavaBeans properties are created by adding the <form-property> tag in Struts Config file (and also declaring its Java type). In above RegisterForm is declared as a DynaActionForm with JavaBeans properties. The type attribute of the <form-property> is the fully qualified Java class name for that JavaBeans property; it cannot be a primitive. For instance int is not allowed. Instead you should usejava.lang.Integer
. You can also initialize the form property,so that the html form shows up with an initial value.