senthil Kumar wrote the following on 1/27/2005 2:19 AM:

  I am getting more than 100 regards from database and print in a JSP by 15 
regards per Page.
  Its is working fine.
  Now i want to set alternative Row background color. I print all the rows between 
the <logic:iterator> in
Struts. any one help me.

I created a simple reusable tag file for this because it's annoying to have to recode that logic on all the pages that need it. Usage is


<c:forEach items="${associates}" var="associate" varStatus="status">
    <tags:AltRowColor status="${status.index}"/>

You need to code in your style sheet a color for "odd" and "even" or you can over-ride that and provide your own. Also if you have a style you need to use for the row other than the odd/even you can provide that as well. For example:

<tags:AltRowColor status="${status.index}" styleClass="myRowCSSclass"/>

Since you are using logic:iterate replace status.index with just the logic indexId (or whatever it's called.. I forgot how to use logic:iterate since moving to JSTL c:forEach)

The tag file is:

AltRowColor.tag:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
<%@ attribute name="status" %>
<%@ attribute name="odd" %>
<%@ attribute name="even" %>
<%@ attribute name="styleClass" %>
<%-- if user doesn't provide an odd or even value it uses odd and even as class names --%>
<c:if test='${even == null || even == "" }'>
<c:set var="even" value="even"/>
</c:if>
<c:if test='${odd == null || odd == "" }'>
<c:set var="odd" value="odd"/>
</c:if>
<c:choose>
<c:when test="${(status +1) % 2 != 0 }">
<tr class="${odd} ${styleClass}">
</c:when>
<c:otherwise>
<tr class="${even} ${styleClass}">
</c:otherwise>
</c:choose>




--
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to