I've been developing with Tapestry since version 3. I finally reached the 
conclusion that templates like below are evil. :) The main reason for them in 
T4 was template reloading, so you had fast turnaround time when developing. In 
T5, you get page & component class reloading, as well, so the primary driver 
behind putting any logic in the template is gone. Here are a few reasons why I 
find templates like below evil:  

  1) It makes pages more brittle and prone to break during refactoring
  2) It makes it easier for a designer (or anyone, really) to hose the 
page/component (there's just a lot more stuff in there to break by accident)
  3) It's considerably more difficult to understand/read (and therefore to 
maintain!)

Here's a T5 version of your snippet below:

.tml:

<t:loop source="collection" value="currentObject" index=index">
    <t:if test="okToRenderItem">
        <t:if test="hasColumnsAndItems">
            <t:if test="atRowEnd">
              <t:outputraw value="trTags"/>
            </t:if>
        </t:if>
    </t:if>
</t:loop>

.java:

@Property
private int index;

@Property 
private Object currentObject;

public String  getTrTags() { 
        return "<tr></tr>";
}

public boolean isOkToRenderItem() { /* whatever your original method was */ }

public boolean isHasColumnsAndItems() {
        return Math.min(tableColumns, itemsPerPage) > 0;/*since you're 
referencing these as properties in your page, I'm assuming they are available 
as properties in your page already*/
}

public boolean isAtRowEnd() {
        return ((index - cursor) % Math.min(tableColumns, itemsPerPage)) == 
0;/* again assuming that cursor, tableColumns, and itemsPerPage are available 
as properties in your page/component class... possibly as parameter values?)*/
}

Maybe it's just me... I like the T5 version a lot better. :)

Robert

On Sep 17, 2011, at 9/174:19 PM , Ken in Nashua wrote:

> 
> 
> 
> 
> 
> 
> 
> 
> 
> Thanks Thiago... I didn't think it unreasonable to have fundamental ops to 
> take code like this...
> 
>                <span jwcid="foreachitem@For" source="ognl:collection" 
> value="ognl:currentObject" index="ognl:index">
>                    <span jwcid="@If" condition="ognl:okToRenderItem">
> 
>                        <span jwcid="@If" condition="ognl:( 
> @java.lang.Math@min(tableColumns, itemsPerPage) )">
>                            <span jwcid="@If" condition="ognl:((index - 
> cursor) % @java.lang.Math@min(tableColumns, itemsPerPage) ) == 0">
>                                <span jwcid="@Insert" value="</tr><tr>" 
> raw="true"/>
>                            </span>
>                        </span>    
> 
> and have tap5 honor the same semantic (arithmetic and method calls) in some 
> way or another...
> 
> I refuse to violate the page code and self contained components is pure 
> tapestry anyway.
> 
> It seems I need chenelle...
> 
> Can you recommend a chenelle version for tap 5.3.0 ?
> 
> Thank You
> 
> 
>                                         


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

Reply via email to