You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Campbell <mi...@gmail.com> on 2005/11/29 20:01:31 UTC

What's the pattern?

I'm a brand new Tapestry user, so I'll probably be having a lot of
silly questions for a while... a priori apologies for that.

I'm looking at converting an existing application, and one commonly
used idiom there is that it displays a table of items.  The way it
does this is that it iterates over the list of the items, using a jsp
tag which "knows" what the index of the list is.

It uses this index along with a modulo operator to insert a new row in
the table if the number of columns is some fixed value.

Something like this:

<tag:iterate list="myItemList">

   <!-- normal html stuff here -->

  <tag:if "list.index % 4 == 0">
     <!-- end this row, start a new one... -->
     </tr>
     <tr>
  </tag:if>
</tag:iterate>

I think I'd use the @ForEach component for the iteration, but what's
the "tapestry way" of making new rows?

Thanks

-- 
Michael Campbell


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


Re: What's the pattern?

Posted by Todd O'Bryan <to...@mac.com>.
On Nov 29, 2005, at 3:07 PM, Michael Campbell wrote:

> "Patrick Casey" <pa...@adelphia.net> writes:
>
>> <table>
>> 	<span jwcid="@Foreach" source="ognl:list" value="ognl:currentValue"
>> element="tr">
>> 		<td>
>> 			<span jwcid="@Insert" value="ognl:currentValue.foo"
>> />
>> 		</td>
>> 	</span>
>> </table>
>
> Thanks Patrick.  I don't know what I'm looking at yet there, but I
> have both Howard's and Kent's books, so I know what to look FOR...
>

This actually doesn't do what you want. This takes a list of elements  
(the source) and prints each one in a separate cell in a single long  
row.

You wanted a way to introduce new rows each n elements. You'd do that  
like this in your .html file:

<table>
<tr>
<span jwcid="@Foreach" source="ognl:list" value="ognl:currentValue"  
index="ognl:i">

<span jwcid="@Conditional" condition="ognl:i + 1 % n == 0">
</tr><tr>
</span>

<td>
	<span jwcid="@Insert" value="ognl:currentValue.displayValue" />
</td>

</tr>
</span>

In your .page file, you need:

<property-specification name="list" type="java.util.List" />
<property-specification name="currentValue"  
type="your.package.ClassName" />
<property-specification name="i" type="int" />

So, what this does is creates a table and a row and loops over each  
of the values in the list, setting currentValue to each one in turn  
and updating the index variable i.

The @Conditional checks to see if i + 1 % n (you should stick in some  
real number there or have another property for n) is 0, and ends the  
current row and starts a new one if that's the case. (I think this is  
buggy. You may get a blank row at the end.)

The @Insert replaces itself with the output of the getDisplayValue()  
method of the currentValue object which is, by virtue of the two  
tags, the contents of a table cell.

Given all of that, it may be easier to use the ContribTable  
component, where you can specify the size of the table and which  
element should go where, but it's do-able.

Todd

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


Re: What's the pattern?

Posted by Michael Campbell <mi...@gmail.com>.
"Patrick Casey" <pa...@adelphia.net> writes:

> <table>
> 	<span jwcid="@Foreach" source="ognl:list" value="ognl:currentValue"
> element="tr">  
> 		<td>
> 			<span jwcid="@Insert" value="ognl:currentValue.foo"
> />
> 		</td>
> 	</span>         
> </table>

Thanks Patrick.  I don't know what I'm looking at yet there, but I
have both Howard's and Kent's books, so I know what to look FOR...



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


RE: What's the pattern?

Posted by Patrick Casey <pa...@adelphia.net>.
<table>
	<span jwcid="@Foreach" source="ognl:list" value="ognl:currentValue"
element="tr">  
		<td>
			<span jwcid="@Insert" value="ognl:currentValue.foo"
/>
		</td>
	</span>         
</table>

> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Michael Campbell
> Sent: Tuesday, November 29, 2005 11:02 AM
> To: tapestry-user@jakarta.apache.org
> Subject: What's the pattern?
> 
> 
> I'm a brand new Tapestry user, so I'll probably be having a lot of
> silly questions for a while... a priori apologies for that.
> 
> I'm looking at converting an existing application, and one commonly
> used idiom there is that it displays a table of items.  The way it
> does this is that it iterates over the list of the items, using a jsp
> tag which "knows" what the index of the list is.
> 
> It uses this index along with a modulo operator to insert a new row in
> the table if the number of columns is some fixed value.
> 
> Something like this:
> 
> <tag:iterate list="myItemList">
> 
>    <!-- normal html stuff here -->
> 
>   <tag:if "list.index % 4 == 0">
>      <!-- end this row, start a new one... -->
>      </tr>
>      <tr>
>   </tag:if>
> </tag:iterate>
> 
> I think I'd use the @ForEach component for the iteration, but what's
> the "tapestry way" of making new rows?
> 
> Thanks
> 
> --
> Michael Campbell
> 
> 
> ---------------------------------------------------------------------
> 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