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

Shi*_*jee 0 java spring jsp spring-mvc java-ee

我坚持我的代码,我需要帮助。我想访问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)"/>
Run Code Online (Sandbox Code Playgroud)

org.springframework.beans.NotReadablePropertyException: Invalid property 'documentlist' of bean class [gc.dms.bean.PolicyDocumentSetForm]
Run Code Online (Sandbox Code Playgroud)

Abh*_*yak 5

例外:

org.springframework.beans.NotReadablePropertyException: Invalid property 'documentlist' of bean class [gc.dms.bean.PolicyDocumentSetForm]
Run Code Online (Sandbox Code Playgroud)

可能在

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

解,

正在考虑您添加了Policydocumentsetforminsaance commandNamemodelAttribute并尝试使用spring checkbox(<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>
Run Code Online (Sandbox Code Playgroud)

注意:确保getter和setter在Policydocumentsetform和中可用Document