我有以下代码:
<c:forEach var="pjawaban" items="${pilihanjawaban}" varStatus="status">
<c:choose>
<c:when test="${pjawaban.idPenelitian==penelitian.idPenelitian}">
<div class="controls span9">
<label class="radio span3">
<input type="radio" name="jawaban${status.count}" disabled="true" value="${pjawaban.pilihanJawaban}"/>
${pjawaban.pilihanJawaban},${pjawaban.idPenelitian},${status.count}
</label>
<label class="span">
Score
</label>
<label class="span">
<input type="text" name="nilai${status.count}" value="${pjawaban.scoreJawaban}" disabled="true"/>
</label>
</div>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</c:forEach>
这个变量有六个索引,但我只想用4个索引。我只想在条件为真时计算索引,例如:
if(condition){
a++;
}else{
}
有人可以帮我在jstl上实现这个吗?
谢谢!
答案 0 :(得分:0)
<c:forEach var="pjawaban" items="${pilihanjawaban}" varStatus="status">
<c:if test="${pjawaban.idPenelitian==penelitian.idPenelitian}">
<div class="controls span9">
<label class="radio span3">
<input type="radio" name="jawaban${status.count}" disabled="true" value="${pjawaban.pilihanJawaban}"/>
${pjawaban.pilihanJawaban},${pjawaban.idPenelitian},${status.count}
</label>
<label class="span">
Score
</label>
<label class="span">
<input type="text" name="nilai${status.count}" value="${pjawaban.scoreJawaban}" disabled="true"/>
</label>
</div>
</c:if>
而不是使用c:在c中没有动作时:否则
答案 1 :(得分:0)
现在为您的解决方案:
<c:forEach var="pjawaban" items="${pilihanjawaban}" varStatus="status">
<c:if test="${(pjawaban.idPenelitian eq penelitian.idPenelitian) && (status.count le 4) }">
<div class="controls span9">
<label class="radio span3">
<input type="radio" name="jawaban${status.count}" disabled="true" value="${pjawaban.pilihanJawaban}"/>
${pjawaban.pilihanJawaban},${pjawaban.idPenelitian},${status.count}
</label>
<label class="span">
Score
</label>
<label class="span">
<input type="text" name="nilai${status.count}" value="${pjawaban.scoreJawaban}" disabled="true"/>
</label>
</div>
</c:if>
</c:foreach>