[英]Can I use a Hashtable in a unified EL expression on a c:forEach tag using JSF 1.2 with JSP 2.1?
[英]How to update value in <c:set> tag using EL inside a <c:foreach> tag
我有一個list
,其中包含一些對象。 這些對象有一個hours
字段。
在<c:foreach>
中,我正在迭代列表並獲取對象。
現在我想在一個totalHours
變量中總結所有迭代對象的hours
字段。
我的代碼:
<c:forEach var="attendance" items="${list }" varStatus="rowCounter1">
<tr>
<td><c:out value="${rowCounter1.count}"></c:out></td>
<td><c:out value="${attendance.date }"></c:out></td>
<td><c:out value="${attendance.inTime }"></c:out></td>
<td><c:out value="${attendance.outTime }"></c:out></td>
<td><c:out value="${attendance.interval }"></c:out></td>
<c:set var="totalHours" value="${attendance.Hours += attendance.Hours }"
target="${attendance}"</c:set>
</tr>
</c:forEach>
我正在嘗試這個,但它給了我以下錯誤:
javax.el.ELException: Failed to parse the expression [${attendance.Hours += attendance.Hours }
在 Java 中,它看起來像這樣:
// before the loop:
int totalHours = 0;
for (Attendance attendance : list) {
totalHours = totalHours + attendance.getHours();
}
所以在 JSTL 中做同樣的事情:
<c:set var="totalHours" value="${0}"/>
<c:forEach var="attendance" items="${list }" varStatus="rowCounter1">
...
<c:set var="totalHours" value="${totalHours + attendance.hours}"/>
</c:forEach>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.