【问题标题】:How to access properties of arraylist associated with a model bean object using spring tags?如何使用spring标签访问与模型bean对象关联的arraylist的属性?
【发布时间】:2014-04-09 12:40:35
【问题描述】:

我的代码卡住了,我需要帮助。我想访问jsp页面中arraylist的属性。下面给出的是代码 sn-ps 和错误。任何帮助将不胜感激!

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]

【问题讨论】:

  • 如何将 Policydocumentsetform 传递给控制器​​中的 jsp?除此之外 - 你是否为 documentList 制作了 getter 方法?
  • 使用这个命令Name="policydocumentsetform"
  • Policydocumentsetform 是否定义了getDocumentList()?如果没有,它也需要。
  • 错误与您显示的EL不符。
  • 我知道 EL 不包含错误,请在上面查看我的问题.. 我关心的是弹簧标签 'form:checkbox' 的弹簧 'path' 属性

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


【解决方案1】:

例外:

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 并尝试使用 spring 复选框(&lt;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>

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

【讨论】:

  • 是的,它工作得很好,但我有一个查询..而不是写这个 path="documentList[${documentLoop.index}].ynChkBox" ,它不能写成这样 path="文档[${documentLoop.index}].ynChkBox"??我这么说是因为 document 是 'policydocumentsetform.documentList' 的已声明别名。
  • 如果运行良好,请用 +1 接受,documentList[${documentLoop.index}].ynChkBox 是正确的,你不能写 document[${documentLoop.index}].ynChkBox 这意味着文档属性在 Policydocumentsetform 中不可用,但在 private ArrayList&lt;Document&gt; documentList 中不可用。跨度>
猜你喜欢
  • 2014-04-21
  • 1970-01-01
  • 2019-05-25
  • 2013-02-18
  • 1970-01-01
  • 2021-08-03
  • 2014-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多