Alternating Row colors in tables in Struts

| No Comments

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!

Leave a comment

Twitter

Sponsors!

About this Entry

This page contains a single entry by dbs published on October 5, 2008 10:03 AM.

Identify that Restaurant! was the previous entry in this blog.

The Weekend, Redux is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.