1. use the 'index' attribute of loop:
<t:loop source="topnewsdatas" value="newsItem" index="indexProp">
2. add the indexProp to your page class
@Property private int indexProp;
3. use a property symbol for the appropriate style attribute (i'm
assuming the <tr>)
<tr class="linkboxbold" style="background-color: ${alternateColour}">
4. implement the logic in your page class
public String getAlternateColour()
{
return indexProp % 2 == 0 ? "#CDCECC" : "#FFFFFF";
}
5. enjoy.
On 22/02/2012 5:31 PM, karthi wrote:
Hi,
I have used loop in my code to layout a table like structure and everything
works fine in that loop in UI (shows three rows with background color and
datas), However I have one doubt in that for all the three rows it shows the
same background color #CDCECC but I want to change the color like below
if (index%2 == 0) {
style="background-color: #CDCECC"
} else {
style="background-color: #FFFFFF"
}
<t:loop source="topnewsdatas" value="newsItem">
<table width="100%" cellpadding="2" cellspacing="0">
<tr class="linkboxbold" style="background-color: #CDCECC">
<td style="vertical-align:top;">
<p class="image">
${newsItem.imgUrl}
</p>
</td>
<td width="100%">
<p class="text">
/ ${newsItem.pubDate} /
</p>
<p class="link">
${newsItem.detailLink} ${newsItem.title}
<br />
</p>
<p class="text">${newsItem.description}</p>
</td>
<td align="right">
layout/images/next_new.gif
</td>
</tr>
</table>
</t:loop>
Please any one help me to achieve this??
--
View this message in context:
http://tapestry.1045711.n5.nabble.com/how-to-get-the-index-in-tapestry-loop-and-change-background-color-of-a-table-tp5504289p5504289.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org