Implement multi-row form submission in struts Framework

Source: Internet
Author: User

In the struts framework, there are often multiple rows of forms. How can we effectively use the automatic collection mechanism provided by the struts framework to process them? A simple method is provided here.
You can use List to solve this problem. every element in List is a valid object.
For example:
Class... TestBean ...{
Private List test = new ArrayList ();
...
...
Public Lisg getTest (){....}
}
Each element in the test List is a SubTestBean.
Class... SubTestBean {
Private int id;
Private String name;
Get ...(){}
Set ...(...){}
}
In this way, we can process multiple rows as follows (assume that testbean has been placed in the request ):




In this way, the information will be automatically displayed, but it cannot be automatically collected now. How can this information be correctly recycled?
We need to do some operations on the test List to inherit an ArrayList and overwrite its get (I) method.
For example:
Class TestArrayList extends ArrayList {

/*
* (Non-Javadoc)
*
* @ See java. util. List # get (int)
*/
Public Object get (int index ){
While (index> = size ()){
Add (new SubTestBean ());
}
Return super. get (index );
}
}

Then we put the private List test = new ArrayList () in TestBean ();
Replace with private List test = new TestArrayList ();
This will enable automatic collection.

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.