Wednesday, August 21, 2013

Alternating colors in HTML table with not working

Alternating colors in HTML table with not working

I've created a JSP that has the following style,
<style type="css/text">
tr.color1{background-color:#00FCFF;}
tr.color2{background-color:#c1bfbb;}
</style>
I model an attribute in the JSP and render a table. Since I iterate over
the List that is modelled in my JSP, I have to set up a logic for
alternating HTML table rows.
I have used JSTL and have the following code:
<c:forEach items="${rSList}" var="rS" varStatus="rowCounter">
<tr class="${rowCounter.index % 2 == 0 ? 'color2':'color1'}">
<td style="padding-left: 4px;" >
<font face="verdana"><c:out value="${rS.NAME}" /></font>
</td>
<td style="padding-left: 4px;" >
<font face="verdana"><c:out value="${rS.AVAILABLE}"
/></font>
</td>
<td style="padding-left: 4px;" >
<font face="verdana"><c:out value="${rS.OWNER}" /></font>
</td>
I used Firebug and saw that indeed the class get alternated as :
<tr class="color2">
<!- td data gets displayed here without color2 background-->
<tr class="color1">
<!- td data gets displayed here without color1 background-->
<tr class="color2">
<tr class="color1">
<tr class="color2">
This means that the class is getting picked but the background color
doesn't change. Appreciate any help.

No comments:

Post a Comment