【问题标题】:Adding form:checbox inside forEach在 forEach 中添加表单:复选框
【发布时间】:2011-10-28 23:14:46
【问题描述】:

我在 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页面中设置复选框

【问题讨论】:

    标签: forms jsp spring-mvc jstl


    【解决方案1】:

    我假设您的命令对象具有List&lt;Feature&gt; 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>
    

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 2019-09-07
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多