>
> I'm using the logic:iterate tag to render a table. Now
> I need to show alternating colours for odd and even
> table rows. How do I achieve this effect together with
> the logic:iterate tag?
>
What you could do is create a color alternating bean. I've made one for
similar uses. Here's how mine is layed out:
--ColorAlternator--
public String getNext()
public String getCurrent()
public void setColor1(String color1)
public void setColor2(String color2)
public void setColor3(String color3)
public int getNumberOfColors()
public void setNumberOfColors(int numOfColors) // should be either 2 or 3
-------------------
You just implement it so that each call to next sets the current color to
the next one and returns it. Actually, this is really just a String
alternator but the intent is for color names.
I suppose that I could have used some kind of circular list and then enabled
it to handle any number of colors, but my assumption was that you probably
never have a use for more than 3 colors. It makes the implementation pretty
simple.
Then you can use this bean whenever you want. For example:
----- JSP page -------------
<jsp:useBean id="color" class="ColorAlternator"/>
<jsp:setProperty name="color" property="color1" value="white"/>
<jsp:setProperty name="color" property="color2" value="oldlace"/>
<table>
<logic:iterate ....>
<tr bgcolor='<jsp:getProperty name="color" property="next">'>
<td>content</td>
</tr>
</logic:iterate>
</table>
----------------------------
Hope this helps.
Scott