我在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页面中的复选框
答案 0 :(得分:0)
我假设您的命令对象具有List<Feature> features
属性,并且您希望在提交表单时列表中每个Feature对象的复选框状态。你可以尝试:
<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>