Increment counter with loop Increment counter with loop java java

Increment counter with loop


Try the following:

<c:set var="count" value="0" scope="page" />//in your loops<c:set var="count" value="${count + 1}" scope="page"/>


The varStatus references to LoopTagStatus which has a getIndex() method.

So:

<c:forEach var="tableEntity" items='${requestScope.tables}' varStatus="outer">   <c:forEach var="rowEntity" items='${tableEntity.rows}' varStatus="inner">                    <c:out value="${(outer.index * fn:length(tableEntity.rows)) + inner.index}" />    </c:forEach></c:forEach>

See also:


You can use varStatus in your c:forEach loop

In your first example you can get the counter to work properly as follows...

<c:forEach var="tableEntity" items='${requestScope.tables}'>   <c:forEach var="rowEntity" items='${tableEntity.rows}' varStatus="count">                    my count is ${count.count}    </c:forEach></c:forEach>