You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Craig Turner <cr...@recalldesign.com> on 2005/03/03 10:12:46 UTC
Alternating styles across rows
I've spent some time trying to work out how to get tapestry to render
rows with alternating styles. Try to imagine a report where the first
row is blue, then next white, the next blue and so on.
The rendered content might look like is this:
<tr>
<td style="whiteStyle">
Alice
</td>
<td style="whiteStyle">
$150
</td>
</tr>
<tr>
<td style="blueStyle">
Bob
</td>
<td style="blueStyle">
$130
</td>
</tr>
In order to produce that, I thought I'd need to write something a bit
like this:
<span jwcid="forEachComponent">
<tr>
<td class="ognl:styleMethod">
{content}
</td>
</tr>
</span>
These are the things I've tried:
<td style="ognl:methodToGetStyle">
-> as above - this doesn't work because the ognl tag doesn't get
expanded.
@Insert that calls a java method that outputs raw html td tags
-> doesn't work because tapestry escapes the < and > tags (this is also
a really ugly approach because you have to also do an insert for the
closing td tag later on)
@Insert raw="true"
-> doesn't work because tapestry strips the < and > tags
:)
Does anyone have a in-spirit solution to this? I've been looking at
tapestry on the web and have found a few tutorials, and I have been
working through the Ship book, but I haven't yet found any examples to
this sort of problem. I could implement a custom component (I haven't
done any yet but imagine this would be straightforward) but I wanted to
ask whether I'd missed anything before doing that.
- C
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Alternating styles across rows
Posted by "t.n.a." <tn...@sharanet.org>.
Craig Turner wrote:
>I've spent some time trying to work out how to get tapestry to render
>rows with alternating styles. Try to imagine a report where the first...
>
>
>Does anyone have a in-spirit solution to this? I've been looking at
>
From what I've read, it seems you could use the EvenOdd class. With
it, you could do something like this:
<span jwcid="forEachComponent">
<tr>
<td class="ognl:(new EvenOdd()).next.isEven ? styledefinition1 : styledefinition2">
{content}
</td>
</tr>
</span>
At the moment, all I can guarantee is that thy syntax I used is
incorrect :), but I'm fairly new to tapestry myself and try to pick up
the concepts instead of the syntax.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Alternating styles across rows
Posted by Bartek Wasko <ba...@consol.pl>.
Another possibility (for alternating styles across rows):
<span jwcid="@Foreach" source="ognl:myRows" index="ognl:rowIndex"
value="ognl:myRow" element="tr" class="ognl:style">
{content}
</span>
and in corresponding class you will find:
private int rowIndex;
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
public String getStyle() {
if (rowIndex % 2 == 0) {
return "tableRowOdd";
} else {
return "tableRowEven";
}
}
----- Original Message -----
From: "Craig Turner" <cr...@recalldesign.com>
To: "tapestry-user" <ta...@jakarta.apache.org>
Sent: Thursday, March 03, 2005 10:12 AM
Subject: Alternating styles across rows
> I've spent some time trying to work out how to get tapestry to render
> rows with alternating styles. Try to imagine a report where the first
> row is blue, then next white, the next blue and so on.
>
> The rendered content might look like is this:
>
> <tr>
> <td style="whiteStyle">
> Alice
> </td>
> <td style="whiteStyle">
> $150
> </td>
> </tr>
> <tr>
> <td style="blueStyle">
> Bob
> </td>
> <td style="blueStyle">
> $130
> </td>
> </tr>
>
> In order to produce that, I thought I'd need to write something a bit
> like this:
> <span jwcid="forEachComponent">
> <tr>
> <td class="ognl:styleMethod">
> {content}
> </td>
> </tr>
> </span>
>
> These are the things I've tried:
> <td style="ognl:methodToGetStyle">
> -> as above - this doesn't work because the ognl tag doesn't get
> expanded.
>
> @Insert that calls a java method that outputs raw html td tags
> -> doesn't work because tapestry escapes the < and > tags (this is also
> a really ugly approach because you have to also do an insert for the
> closing td tag later on)
>
> @Insert raw="true"
> -> doesn't work because tapestry strips the < and > tags
>
>
> :)
>
> Does anyone have a in-spirit solution to this? I've been looking at
> tapestry on the web and have found a few tutorials, and I have been
> working through the Ship book, but I haven't yet found any examples to
> this sort of problem. I could implement a custom component (I haven't
> done any yet but imagine this would be straightforward) but I wanted to
> ask whether I'd missed anything before doing that.
>
> - C
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Alternating styles across rows
Posted by Christian Haselbach <ch...@tngtech.com>.
Quoting Craig Turner <cr...@recalldesign.com>:
> In order to produce that, I thought I'd need to write something a bit
> like this:
> <span jwcid="forEachComponent">
> <tr>
> <td class="ognl:styleMethod">
> {content}
> </td>
> </tr>
> </span>
>
> These are the things I've tried:
> <td style="ognl:methodToGetStyle">
> -> as above - this doesn't work because the ognl tag doesn't get
> expanded.
>
> @Insert that calls a java method that outputs raw html td tags
> -> doesn't work because tapestry escapes the < and > tags (this is also
> a really ugly approach because you have to also do an insert for the
> closing td tag later on)
You are looking for the @Any component. Have a look into the components
reference:
http://jakarta.apache.org/tapestry/doc/ComponentReference/index.html
<td jwcid="@Any" style="ognl:methodToGetStyle"> ...
HTH
Ciao Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org