Introduce new struts features: lazyactionform

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.