如何使用spring标签访问与模型bean对象关联的arraylist的属性?

时间:2014-04-09 12:40:36

标签: java spring jsp java-ee spring-mvc

我被我的代码困住了,我需要帮助。我希望能够访问jsp页面中arraylist的属性。下面给出的是代码片段和错误。任何帮助将不胜感激!

public class Policydocumentsetform implements Serializable{
    ...
          private ArrayList<Document> documentList;
    ...
}



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



<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)"/>

org.springframework.beans.NotReadablePropertyException: Invalid property 'documentlist' of bean class [gc.dms.bean.PolicyDocumentSetForm]

1 个答案:

答案 0 :(得分:5)

例外:

org.springframework.beans.NotReadablePropertyException: Invalid property 'documentlist' of bean class [gc.dms.bean.PolicyDocumentSetForm]

可能在

<form:checkbox path="documentlist.ynChkBox" //Here, is the problem
               cssClass="genradio"
               value="-1"
               onclick="selectCheckBox(event.keyCode,this)"/>

解,

我在考虑您已将Policydocumentsetform个问题添加为commandNamemodelAttribute,并尝试使用弹簧复选框(<form:checkbox..),如果是这样的话:

<form:form commandName="policydocumentsetform"...>

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

<子>注意: 确保PolicydocumentsetformDocument

中提供了getter和setter