You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by karthi <ra...@snovabits.net> on 2012/02/22 07:31:51 UTC
how to get the index in tapestry loop and change background color
of a table
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to get the index in tapestry loop and change background
color of a table
Posted by karthi <ra...@snovabits.net>.
I was just started to work in that way, but you saved my time!!
Thank you so much it works as expected
And your explanation is really very simple for beginners!!
--
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-tp5504289p5504375.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to get the index in tapestry loop and change background color
of a table
Posted by Paul Stanton <pa...@mapshed.com.au>.
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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to get the index in tapestry loop and change background color
of a table
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 22 Feb 2012 04:31:51 -0200, karthi <ra...@snovabits.net>
wrote:
> Hi,
Hi!
Have you ever read the Loop documentation? There's an index parameter
there.
<t:loop t:index="index" ...>
<p style="${pStyle}">
@Property
private int index;
public String getStyle() {
if (index%2 == 0) {
return "background-color: #CDCECC";
} else {
return="background-color: #FFFFFF"
}
}
Please read the documentation before posting questions. It'll save yours
and ours time.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org