jysh0922 2008-08-14 16:26
浏览 219
已采纳

ActionForm嵌套对象数组

 public class TestForm extends ActionForm {
    private String address;
    private String method;
    private TestSubForm[] subTest;
                ..........................
}
public class TestSubForm extends ActionForm {
    private String id;
    private String name ;
    private String value;
                ........................
}

有两个存在这种嵌套关系的数组,TestSubForm[] 数组大小不确定。

jsp页面如下:

<input name="address" type="text" value="">

     <input name="name" type="text" value="">
     <input name="value" type="text" value="">


     <input name="name" type="text" value="">
     <input name="value" type="text" value="">


     <input name="name" type="text" value="">
     <input name="value" type="text" value="">

在action中怎么才能直接TestForm 对象,并且可以遍历TestSubForm数组


问题补充:
假如按 zhai puhong的方法把

private TestSubForm[] subTest;

改为

private list subTest;

那么在action处理类中

public class ValuationAction extends DispatchAction {

public ActionForward list(......){

TestForm testForm = new TestForm();


testForm = (TestForm)form;

if(testForm!=null){

List subFormList = testForm.getSubTest();

}

return mapping.findForward("list");

}

}

好像subFormList是空的 并不是我希望的TestSubForm集合
  • 写回答

4条回答 默认 最新

  • piccbj 2008-08-14 16:53
    关注

    在AppFuse 中ssh就有form套用form的例子
    [code="java"]
    public class UserForm
    extends BaseForm
    implements java.io.Serializable
    {

    ……
    protected AddressForm address = new AddressForm();
    

    ……
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?