2014-04-08 35 views
1

有一些属性的父bean,其中一个是ArrayList。现在这个ArrayList被初始化为一个子bean的属性。现在我怎样才能访问这些属性在jsp中使用弹簧窗体标签?其实我需要遍历ArrayList并访问它的属性。我下面的代码中给出,如何使用弹簧窗体标签访问数组列表的属性?

<c:forEach var="documentlist" items="${policydocumentsetform.documentList}">  
<c:if test="${documentlist.txtDisableCheckBox=='N'}"> 
    <form:checkbox path="documentlist.ynChkBox" cssClass="genradio" value="-1" onclick="selectCheckBox(event.keyCode,this)"/> 
</c:if> 

错误被抛出,因为这path="documentlist.ynChkBox"的,请帮助!

+0

在路径而不是documentlist.ynChkBox中使用与您的标记相关的模型属性 –

+1

你能说一下你的模型属性究竟意味着什么?对不起,我不熟悉这些术语... –

+0

创建表格的类使用注释@实体/ @表。 在你的路径中使用的那个类中存在的变量名。 –

回答

1

综观JSP代码,你需要确保你的形式和它的属性如下:

public class Policydocumentsetform implements Serializable{ 
     ... 
         //I would rather go with List 
     private ArrayList<Document> documentList; 
     ... 
    } 

其中文档是包含豆:

public class Document implements Serializable{ 
     ... 
     private String txtDisableCheckBox; 
     private String ynChkBox; 
     ... 
    } 

试试这个方法:

<c:forEach var="document" items="${policydocumentsetform.documentList}" varStatus="documentStatus">  
     <c:if test="${document.txtDisableCheckBox=='N'}"> 
      <form:checkbox path="document[${documentStatus.index}].ynChkBox" cssClass="genradio" value="-1" onclick="selectCheckBox(event.keyCode,this)"/> 
     </c:if> 
    </c:forEach> 
+0

尝试过但没有成功,org.springframework.beans.NotReadablePropertyException:Bean类(父bean)的无效属性'document [0]' –

+0

我的理解是它试图在bean中查找属性document.ynChkBox对象'policydocumentsetform',但实际上它位于用于初始化'policydocumentsetform'的数组列表的属性的bean对象'policydocumentsetchildform'中。所以需要将此路径指向子bean对象,以便可以找到该属性。 –

+0

确保你有我的答案中提到的属性。通过查看jsp中的代码,txtDisableCheckBox和ynChkBox不能直接作为子表单的子元素,因为您正在检查每个列表元素的条件 - 而不是文档列表的子元素。 – Prasad

相关问题