This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic iterate

 
Nicolas Flammel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a logic iterate tag that lists the rows in the table form from a collection.
Is it possible to have alternate row colors within the iterate tag? How?
 
Markus Jura
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it is.
i have hear an very simple example. so you can realize two different colors and for each row the color switched:

code:
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<% String[] myCollection = {"entry1", "entry2", "entry3", "entry4", "entry5"}; %>

<table border="0" cellpadding="5" cellspacing="0">
<% String bgColor="#999999"; %>

<logic:iterate id="entry" indexId="rowIndex" collection="<%=myCollection%>" type="java.lang.String">
<tr bgcolor="<%=bgColor%>">
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
</tr>
<% bgColor = (rowIndex.intValue() % 2 == 0) ? "#FFFFFF" : "#999999"; %>
</logic:iterate>
</table>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic