You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ken nashua <nh...@hotmail.com> on 2007/10/08 20:27:29 UTC

does T-4.1.* have a COUNT component?

Ok I tried a custom Loop hybrid but that failed to do uncoordinated indices between collection and loop.

All I want to do is increment a count within the template and act on it when it reaches a certain value and then reset it.

IE. render <TR> tag every 3 iterations of my outer For loop.

Does this exist in Tapestry?

Best regards
Ken in nashua
_________________________________________________________________
Climb to the top of the charts!  Play Star Shuffle:  the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct

Re: does T-4.1.* have a COUNT component?

Posted by Mauricio Aldazosa <ma...@gmail.com>.
On 10/8/07, Ken nashua <nh...@hotmail.com> wrote:
>
>
> Ok I tried a custom Loop hybrid but that failed to do uncoordinated
> indices between collection and loop.
>
> All I want to do is increment a count within the template and act on it
> when it reaches a certain value and then reset it.
>
> IE. render <TR> tag every 3 iterations of my outer For loop.
>
> Does this exist in Tapestry?


Hello,

I think that the index parameter of the For component does exactly what you
want.

http://tapestry.apache.org/tapestry4.1/components/general/for.html

Greetings,
Mauricio

Re: does T-4.1.* have a COUNT component?

Posted by Robert Zeigler <ro...@scazdl.org>.
Seems like there are a variety of different ways to do this...
One way would be to have your list be a temporary list of lists...  
you divide your list into sublists of length 3 each, and each sublist  
is an element in a "super" list. Ugly in code. Clean in the template.

Another way to do it would be to use the mod operator in conjunction  
with the if components to determine whether to render a <TR> component.
This one gets a little tricky because tapestry will start complaining  
about invalid nesting of tags... you end up having to write the tags  
out with, say, an input component, with "raw" set to true. So...  
clean in the code, ugly in the template. :)

A modification of approach #2 is something like:

.html:
<span jwcid="@For" source="ognl:collection" index="ognl:index"  
value="ognl:currentObject">
   <span jwcid="@Insert" value="ognl:theText" raw="true"/>
</span>

.java:

public String getTheText() {
   StringBuilder b = new StringBuilder();
   if (getIndex()%3==0) {
     if(getIndex() > 0)  {
       b.append("</tr>");
     }
     b.append("<tr>");
   }
   b.append("<td>");
   b.append(your stuff goes here);
   b.apend("</td>");
   return b.toString();
}

Something along those lines.

Robert

On Oct 8, 2007, at 10/81:27 PM , Ken nashua wrote:

>
> Ok I tried a custom Loop hybrid but that failed to do uncoordinated  
> indices between collection and loop.
>
> All I want to do is increment a count within the template and act  
> on it when it reaches a certain value and then reset it.
>
> IE. render <TR> tag every 3 iterations of my outer For loop.
>
> Does this exist in Tapestry?
>
> Best regards
> Ken in nashua
> _________________________________________________________________
> Climb to the top of the charts!  Play Star Shuffle:  the word  
> scramble challenge with star power.
> http://club.live.com/star_shuffle.aspx? 
> icid=starshuffle_wlmailtextlink_oct


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org