Title: alternate color support in iterate or subtag
I wrote a tag to do this - you can dowload it from Ted Husted's site
 
   http://www.husted.com/about/struts/resources.htm#contributions
 
Niall
-----Original Message-----
From: Steve Salkin [mailto:[EMAIL PROTECTED]]
Sent: 18 June 2001 20:35
To: '[EMAIL PROTECTED]'
Subject: alternate color support in iterate or subtag

Hi-

I've been thinking about how best to handle alternate colors for tables. One approach is simple but ugly:

<table> etc...
  <% String alternatingColor = "firstColor"; %>
  <logic:iterate name="resultSet" id="element">
    <tr>
      <td class="<%=alternatingColor%>">
        <bean:write name="element" property="name"/>
      </td>
    </tr>
    <% if (alternatingColor.equals("firstColor") {
         alternatingColor = "secondColor";
       } else {
         alternatingColor = "secondColor;
       }
     %>
  </logic:iterate>

Now it seems to me that this sort of progression, especially mod 2 (alternation)
must be pretty common. However, it's not clear how best to handle it in a general
way. For example, some people might want to alternate or progressively move through
icons or something else.

So, rather then write and submit an extension to iterate that supports something like
<logic:iterate name="results" id="element" altClass="firstColor, secondColor">

I wonder instead if perhaps a subtag might be a better design. Maybe like the following:

<logic:iterate name="results" id="element">
  <logic:progression name="alternatingClass" value="firstClass, secondClass, thirdClass"/>

  In this case, code within the iterate would be able to access the name "alternatingClass" which would evaluate to "firstClass" for i % 3 == 0, "secondClass" for i % 3 == 1, and so forth.

Even this is sort of ugly though, maybe overdesigned. So if anyone has some feedback about this, if we can sort out a clean design I'll be happy to write it.

S-

Reply via email to