struts多行数据提交解决方案二

来源:互联网 发布:阿里云ubuntu图形界面 编辑:程序博客网 时间:2024/04/28 16:07

ActionForm中的一个ArrayList, 页面上可以用<html:iterator>实现循环显示, 但是怎么样才能在提交时使页面上这些循环显示的数据自动提交呢?

这里主要用到了common-collection包.

FormBean:

代码
import java.util.ArrayList;
import
 java.util.List;
import
 org.apache.commons.collections.Factory;
import
 org.apache.commons.collections.list.LazyList;
import
 org.apache.struts.action.ActionForm;
import
 com.yourcompany.struts.action.UserVo;

public class TestForm extends ActionForm 
{
    
    
public TestForm() 
{
        Factory factory 
= new Factory() 
{   
            
public Object create() 
{   
                
return new
 UserVo();
            }
   
        }

        
this.contents = LazyList.decorate(new
 ArrayList(), factory);
    }


    
// --------------------------------------------------------- Instance Variables

    
private List contents;

    
// --------------------------------------------------------- Methods


    
public List getContents() {
        
return
 contents;
    }


    
public void setContents(List contents) {
        
this.contents =
 contents;
    }


}

如上,ActionForm中的构造函数是必须的.

JSP:

代码
<nested:iterate property="contents" indexId="index">
    
<nested:text property="year"/>
    
<nested:text property="month"/><br/>
</nested:iterate>

 

ok,就这么简单!



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1615225


原创粉丝点击