You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/05/26 18:58:20 UTC

counter in forEach tag?

Hello,
I have this scenario come up occasionally, and have to opt to JSP expressions on the page for a work-around.

 <c:choose>
                  <c:when test="${assetCollection == null}">
                     nothing
                  </c:when>
                  <c:otherwise>
                    <c:forEach var="asset" items="${assetCollection}">


BODY


                      <c:out value="${asset.assetId}" />
                    </c:forEach>
                  </c:otherwise>
                </c:choose>


In the forEach section, I am going to create a rows in a table which will be different colors for each row. How can I put in a counter that I can then change the row color for? Basically, I would like to know what asset I am on in the body.

Thanks,
Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: counter in forEach tag?

Posted by David Schwartz <ds...@arrayone.com>.
1. Add this to your forEach...

varStatus = "stat"

2. Add this to the rows...

<c:when test = '${stat.count % 2 == 0 }' >
    <c:set var = "backColor" value = "White" >
</c:when>
<c:otherwise>
    <c:set var = "backColor" value = "Yellow" >
</c:otherwise>

This example create alternating colors for odd/even rows.


Quoting Scott Purcell <sp...@vertisinc.com>:

>> Hello,
>> I have this scenario come up occasionally, and have to opt to JSP
>> expressions on the page for a work-around.
>>
>>  <c:choose>
>>                   <c:when test="${assetCollection == null}">
>>                      nothing
>>                   </c:when>
>>                   <c:otherwise>
>>                     <c:forEach var="asset" items="${assetCollection}">
>>
>>
>> BODY
>>
>>
>>                       <c:out value="${asset.assetId}" />
>>                     </c:forEach>
>>                   </c:otherwise>
>>                 </c:choose>
>>
>>
>> In the forEach section, I am going to create a rows in a table which will be
>> different colors for each row. How can I put in a counter that I can then
>> change the row color for? Basically, I would like to know what asset I am on
>> in the body.
>>
>> Thanks,
>> Scott
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>


David Schwartz

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: counter in forEach tag?

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
varStatus is good here too, it can give you the "count" of the current 
iteration. With that, for example, you can do a modulo 2 operation for 
alternating bgcolors or style classes.

-Rahul


"Scott Purcell" <sp...@vertisinc.com> wrote on 05/26/2005 12:58:20 PM:

> Hello,
> I have this scenario come up occasionally, and have to opt to JSP 
> expressions on the page for a work-around.
> 
>  <c:choose>
>                   <c:when test="${assetCollection == null}">
>                      nothing
>                   </c:when>
>                   <c:otherwise>
>                     <c:forEach var="asset" items="${assetCollection}">
> 
> 
> BODY
> 
> 
>                       <c:out value="${asset.assetId}" />
>                     </c:forEach>
>                   </c:otherwise>
>                 </c:choose>
> 
> 
> In the forEach section, I am going to create a rows in a table which
> will be different colors for each row. How can I put in a counter 
> that I can then change the row color for? Basically, I would like to
> know what asset I am on in the body.
> 
> Thanks,
> Scott
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>