Up to now, there have been at least three methods for struts actionform.:Common,DynamicAndLazy.
Therefore, you can have a lot of options in your own development. If you are safe first, you can use common. If you prefer XML, use dynamic.
If you are lazy, use lazy actionform.
You only need to select one of the three actionform methods provided by struts.
The following describes lazy actionform:
If you like the powerful features of struts (for example, this actionform has multiple options) and you like quick, lazy actionform is good news for you. this is a bit similar to a commendable feature in WW2, which can reduce the trouble of writing actionform. (struts is absorbing all the good things in WW2. No wonder these two things will be merged into struts it later ).
The sample code is as follows:
Struts-config.xml Configuration
<Struts-config>
<Form-beans>
<Form-bean name = "lazyform" type = "org. Apache. Struts. validator. lazyvalidatorform"/>
</Form-beans>
<Action-mappings>
<Action Path = "/myactionpath" type = "mypackage. myaction" name = "lazyform" Validate = "true"/>
</Action-mappings>
</Struts-config>
JSP webpage
<HTML: Form Action = "/myactionpath">
<H2> simple property example </H2>
Customer Number: <HTML: Text property = "custno"/>
Customer name: <HTML: Text property = "custname"/>
<H2> mapped property example </H2>
Street: <HTML: Text property = "address (street)"/>
Town: <HTML: Text property = "address (town)"/>
State: <HTML: Text property = "address (state)"/>
Country: <HTML: Text property = "address (country)"/>
<H2> indexed property example </H2>
<Logic: iterate id = "Products" property = "Products">
Product Code: <HTML: Text name = "Products" property = "code" indexed = "true"/>
Product Description: <HTML: Text name = "Products" property = "Description" indexed = "true"/>
Product Price: <HTML: Text name = "Products" property = "price" indexed = "true"/>
</Logic: iterate>
</Html: Form>
Action call
Public actionforward execute (actionmapping mapping,
Actionform form,
Httpserveletrequest request,
Httpservletresponse response) throws exception {
// Cast Form to dynabean
Dynabean DYNAFORM = (dynabean) form;
// Use the dynabean
String custno = (string) DYNAFORM. Get ("custno"); // simple
Map address = (MAP) DYNAFORM. Get ("Address"); // mapped
List products = (list) DYNAFORM. Get ("Products"); // indexed
... Etc
}
In action, you can use the beanutils 1.7.0 feature to copy dynaform to the pojo of hibernate at one time!