Alternating Row colors in tables in Struts

5 10 2008

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!

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: