Problem with multiple forEach in JSP - Is there any way to reset varStatus?
807605Oct 3 2007 — edited Oct 3 2007
I am having an extremely annoying problem with a JSP I am working on.
I basically have a collection which I iterate through twice using forEach.
Here is a representation of my first forEach:-
{color:#ff0000}+<c:forEach items="${customers}" var="record" varStatus="loop">+ {color}
{color:#ff0000}+<c:if test="${loop.count == 1}">+
+<c:out value="${loop.count}" />+ {color}
{color:#ff0000}+</c:if>+ {color}
{color:#ff0000}+</c:forEach>+ {color}
The problem is that I want to do some kind of check inside my forEach to see if it is the first time I am iterating through the list so that I can then output a heading. I can get this to work fine in the first forEach either by using "loop.count == 1" or loop.first.
The problem is that it doesn`t work in my second forEach even though the code is practically the same. For some reason the varStatus count is not reset between forEachs. I outputted loop.count and was surprised to see that it basically continues incrementing. So for instance, if the collection was of length 4, the first loop was diplaying 1,2,3,4 and the second loop was displaying 5,6,7,8.
Can anyone help?