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.