This question is related to my previous question :
Jsp iterate trough object list
I want to insert counter that starts from 0 in my for loop, I\'ve tried several
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>
Try the following:
<c:set var="count" value="0" scope="page" />
//in your loops
<c:set var="count" value="${count + 1}" scope="page"/>
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>
what led me to this page is that I set within a page then the inside of an included page I did the increment
and here is the problem
so to solve such a problem, simply use scope="request"
when you declare the variable or the increment
//when you set the variale add scope="request"
<c:set var="nFilters" value="${0}" scope="request"/>
//the increment, it can be happened inside an included page
<c:set var="nFilters" value="${nFilters + 1}" scope="request" />
hope this saves your time