Alternating Row colors in tables in Struts

Have to share this one. I’ve been wracking my brain trying to figure out how to get table rows in a struts and JSTL supported page. I haven’t found an easy example anywhere, but I finally sussed it out. So if you do JSTL and struts based stuff, and want to do those nice ‘greenbar’ like lines on a table, here’s an example of how to do it:

<c:forEach var="rows" items="${registrantList}">
<c:set var="cellColor">
<c:choose>
<c:when test="${cellColor == '#f0f0f0'}">#ffffcc</c:when>
<c:otherwise>#f0f0f0</c:otherwise>
</c:choose>
</c:set>
<s:url id="url" action="coconut/gotoUser" >
<s:param name="rid">${rows.rid}</s:param>
</s:url>
<tr bgcolor="${cellColor}">
<td>
<s:a href="%{url}">${rows.rid}</s:a>
</td>
<td>${rows.lastName}</td>
<td>${rows.firstName}</td>
<td>${rows.company}</td>
<td>${rows.badgeName}</td>
</tr>
</c:forEach>

See? Simple!

About

A wandering geek. Toys, shiny things, pursuits and distractions.

View all posts by

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.