gpt4 book ai didi

java - 如何使用 spring 表单标签访问 arraylist 的属性?

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:27 24 4
gpt4 key购买 nike

有一个具有一些属性的父bean,其中一个属性是ArrayList。现在,这个 ArrayList 已使用子 bean 的属性进行了初始化。现在我如何使用 spring 表单标签访问 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"而引发错误,请帮忙!!

最佳答案

查看 jsp 中的代码,您需要确保您的表单及其属性如下:

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

其中 document 是包含以下内容的 bean:

    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>

关于java - 如何使用 spring 表单标签访问 arraylist 的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935136/

24 4 0