[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4104
  • Last Modified:

JSTL Create Alternating Table Row / Cell Background colors using odd and even % row calculations

Hi Everyone.  I'm just trying to create alternate / alternating  background colors for my list tables
using JSTL.  The varStatus.count field does show 1...2...3...4...5 (array occurs if quuerried) so this the input object is OK.
There must be something else missing.  Thanks  

1) First - Here's the css for the 2 table background color properties:

<STYLE TYPE="text/css">
<!--
.colorBlue
{
background-color:#FFF8EE;
}
.colorWhite
{
background-color:#FFFFFF;
color:white;
}
-->
</STYLE>

Here's the JSTL that should change with the alternating rows.

<c:forEach var="item" items="${sessionScope.AValidArray}"  varStatus="status">
 
 <c:set var="cellColor">
 <c:choose>
 <c:when test="${status.count % 2 == 0}">colorBlue</c:when>
 <c:otherwise>colorWhite</c:otherwise>
 </c:choose>
 </c:set>
 
<TABLE class="cellColor">
<TR><TD>the table colors should alternate with each outoput row</TD></TR>
<TABLE>

</c:forEach>

Note: When I <c:out value="${status.count}"/>  I do get 1...2...3...4...5..6..7..8..9..10...etc

Either the 'whenTest' or the 'cellColor' set up that is not working ? ? ? ?
0
paygo
Asked:
paygo
1 Solution
 
grim_toasterCommented:
Simple solution for you, you need to acquire the cellColor variable using the core tags:

<TABLE class="<c:out value="${cellColor}" />">
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now