Multi-line forms in the Struts framework

xiaoxiao2021-03-06  23

In the Struts framework, you often encounter multi-line forms. How to effectively use the automatic collection mechanism provided by the Struts framework to handle it? It provides a simple method. You can use list to solve this problem. Every element in List It is an effective object. For example: Class ... testbean ... {private list = new arraylist (); ...... ... ......}} where Test List Each element is another subTestBeanclass ... SubtestBean {private int id; private string name; get ... () {} set ... (...) {}} This time we are defining multiple rows It can be handled (assuming TestBean is already in Request): This will be automatically displayed, but it is not able to collect automatically, how can I reclaim correctly? Require it to do a little hand on Test List, inherit an arraylist, override 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; replaced with private list test = new testArrayList (); which can be automatically collected.

转载请注明原文地址:https://www.9cbs.com/read-80272.html

New Post(0)