在 forEach 中添加 form:checkbox

发布于 2024-12-12 17:20:22 字数 766 浏览 2 评论 0原文

我在 jsp 中有一个表,我向其中添加了值,如下所示

<c:forEach items="${features}" var="feature">
<c:choose>
    <c:when test="${feature.present == true}">
        <c:set var="featurePresent" value="REMOVE"/>
    </c:when>
    <c:otherwise>
        <c:set var="featurePresent" value="ADD"/>
    </c:otherwise>
</c:choose>

<tr>
    <td>${feature.name}</td>
    <td>${featurePresent}</td>
    <td><form:checkbox path="" value=""/></td>
</tr>   
</c:forEach>

我正在尝试添加复选框..

我的要素类是

class Feature{
  private String name;
  private boolen present;
  private boolean checkbox

}

如何在 jsp 页面中设置复选框

I have a table in a jsp and i add the value to it as follows

<c:forEach items="${features}" var="feature">
<c:choose>
    <c:when test="${feature.present == true}">
        <c:set var="featurePresent" value="REMOVE"/>
    </c:when>
    <c:otherwise>
        <c:set var="featurePresent" value="ADD"/>
    </c:otherwise>
</c:choose>

<tr>
    <td>${feature.name}</td>
    <td>${featurePresent}</td>
    <td><form:checkbox path="" value=""/></td>
</tr>   
</c:forEach>

I am trying to add the checkbox ..

My Feature class is

class Feature{
  private String name;
  private boolen present;
  private boolean checkbox

}

How can i set the checkbox in the jsp page

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-12-19 17:20:22

我假设您的命令对象有一个 List; features 属性,并且您希望在提交表单时列表中每个功能对象的复选框状态。您可以尝试:

<c:forEach items="${features}" var="feature" varStatus="i">
<c:choose>
    <c:when test="${feature.present == true}">
        <c:set var="featurePresent" value="REMOVE"/>
    </c:when>
    <c:otherwise>
        <c:set var="featurePresent" value="ADD"/>
    </c:otherwise>
</c:choose>

<tr>
    <td>${feature.name}</td>
    <td>${featurePresent}</td>
    <td><form:checkbox path="features[${i.index}].checkbox" value=""/></td>
</tr>   
</c:forEach>

I am assuming your command object has a List<Feature> features property and you want the checkbox state for each Feature object in the list when you submit the form. You may try:

<c:forEach items="${features}" var="feature" varStatus="i">
<c:choose>
    <c:when test="${feature.present == true}">
        <c:set var="featurePresent" value="REMOVE"/>
    </c:when>
    <c:otherwise>
        <c:set var="featurePresent" value="ADD"/>
    </c:otherwise>
</c:choose>

<tr>
    <td>${feature.name}</td>
    <td>${featurePresent}</td>
    <td><form:checkbox path="features[${i.index}].checkbox" value=""/></td>
</tr>   
</c:forEach>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文