J
javaguy
I'm wishing to write JSP pages that have varying background colors for
each line in the list. A simplistic way of doing this is:
<c:forEach items="${myorders}" var="orders" varStatus="loop">
<tr height="20"
<c:if test="${loop.index % 2 eq 0}">bgcolor='#BBBBBB'</c:if> >
<td>Some data</td>
</tr>
</c:forEach>
I was trying to extend the implementing Java class ForEachTag like the
example in the book Struts Recipies (2005, Franciscus, Gurovich,
Manning Publications, Greenwich CT). My version of their IteratorTag
would look like this:
<my:forEachCycle items="${myorders}" var="orders" varStatus="loop"
cycleId="cy" cycleItems="#FF0000 #00FF00 #0000FF">
<tr height="20" bgcolor='<c:set value="${cy}"/>' >
<td>Some data</td>
</tr>
</my:forEachCycle>
The difference between IteratorTag and ForEachTag is that IteratorTag
has a built-in getIndex() method I can use to know where in the list I
am. It also lets me cycle through my list (index is getIndex() %
list_length). I've looked through Google (and deja) for documentation
of org.apache.taglibs.standard.tag.el.core.ForEachTag.java and found
nothing. The ForEachTag descriptions I have found were all for other
implementations (Coocon, etc.) and not applicible here. It is more
frustrating because the forEach tag has ready access to "varStatus"!
So, How do I get an index from within a subclass of ForEachTag.java?
Thanks,
Jerome Mrozak.
each line in the list. A simplistic way of doing this is:
<c:forEach items="${myorders}" var="orders" varStatus="loop">
<tr height="20"
<c:if test="${loop.index % 2 eq 0}">bgcolor='#BBBBBB'</c:if> >
<td>Some data</td>
</tr>
</c:forEach>
I was trying to extend the implementing Java class ForEachTag like the
example in the book Struts Recipies (2005, Franciscus, Gurovich,
Manning Publications, Greenwich CT). My version of their IteratorTag
would look like this:
<my:forEachCycle items="${myorders}" var="orders" varStatus="loop"
cycleId="cy" cycleItems="#FF0000 #00FF00 #0000FF">
<tr height="20" bgcolor='<c:set value="${cy}"/>' >
<td>Some data</td>
</tr>
</my:forEachCycle>
The difference between IteratorTag and ForEachTag is that IteratorTag
has a built-in getIndex() method I can use to know where in the list I
am. It also lets me cycle through my list (index is getIndex() %
list_length). I've looked through Google (and deja) for documentation
of org.apache.taglibs.standard.tag.el.core.ForEachTag.java and found
nothing. The ForEachTag descriptions I have found were all for other
implementations (Coocon, etc.) and not applicible here. It is more
frustrating because the forEach tag has ready access to "varStatus"!
So, How do I get an index from within a subclass of ForEachTag.java?
Thanks,
Jerome Mrozak.