dazzle
dazzle

Reputation: 1346

Highlight alternate rows with logic:iterate

Below code gives me rows with the same color. How to highlight alternate rows in this table with same color

<logic:iterate id="ulist" name="HomeForm" property="userList">
  <tr >
    <td class="content"><bean:write name="ulist" property="username"  />&nbsp;</td>
    <td class="content"><bean:write name="ulist" property="city"  />&nbsp;</td>
</tr>   
</logic:iterate> 

Upvotes: 2

Views: 3073

Answers (3)

berus97
berus97

Reputation: 384

Code without scriplet

<logic:iterate id="myData" name="myListFormBean" property="myList" indexId="tableCounter">
    <tr class="${tableCounter%2==0 ? 'Even':'Odd'}">
</logic:iterate>

Upvotes: 4

cringe
cringe

Reputation: 13950

I'm using this code:

<logic:iterate id="myData" name="myListFormBean" property="myList" indexId="tableCounter">
<%
if (tableCounter % 2 == 0) {
    tdClass = " white ";
} else {
    tdClass = " gray ";
}
%>
    <td class="<%=tdClass%>"></td>
</logic:iterate>

Upvotes: 3

Atropo
Atropo

Reputation: 12531

You've to assign a differente css id for every row, you can use the implicit iterator attributes to obtain that.

Another solution is to use a library like displaytag which automatically adds odd and even attributes to the rows, attributes you can use in the css stylesheet.

Upvotes: 1

Related Questions