Re: outputting expression logic
> I don't think it's ever a good idea to output partial HTML in your page like this. I'll throw one more implementation into the ring. ${var:galleryEntry} http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";> /** * Gallery.java */ import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.annotations.Property; import java.util.Iterator; import java.util.NoSuchElementException; public class Gallery { @Parameter(required = true) private Iterable source; @Parameter(required = true) @Property private Object entry; @Parameter(required = true) private int entriesPerRow; @Parameter private int maxRows; @Property private WrappedIterable rows; @Property private LimitedIterable columns; void setupRender() { rows = new WrappedIterable(source); } public boolean getNeedsPadding() { return !rows.iterator.hasNext() && columns.count < entriesPerRow; } public int getPadding() { return entriesPerRow - columns.count; } public class WrappedIterable implements Iterable { private Iterator iterator; int rows = 0; private WrappedIterable(Iterable iterable) { iterator = iterable.iterator(); } public Iterator iterator() { return new Iterator() { public boolean hasNext() { return (maxRows <= 0 || rows < maxRows) && iterator.hasNext(); } public LimitedIterable next() { if (hasNext()) { ++rows; return new LimitedIterable(iterator, entriesPerRow); } throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException(); } }; } } public class LimitedIterable implements Iterable { int count = 0; private final Iterator iterator; private int limit; private LimitedIterable(Iterator iterator, int limit) { this.iterator = iterator; this.limit = limit; } public Iterator iterator() { return new Iterator() { public boolean hasNext() { return count < limit && iterator.hasNext(); } public Object next() { if (hasNext()) { ++count; return iterator.next(); } throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException(); } }; } } } Josh On Sat, Sep 17, 2011 at 6:40 PM, Ken in Nashua wrote: > > Rob, > > Thanks for the constructive criticism. > > I will give this a whirl... like what I see... > > I am all for good form... and one of the nice things I am excited about T5 is > that it promotes a ton of loose options for achieving good form. > > Appreciate the help and will let you know how I make out. > > - cheers > > KEN > - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
RE: outputting expression logic
Thanks Rob... code ran as-is... auto-paging layout looks sweet I hope to finish this guy up and publish for public consumption by mid week or sooner... I just need to QA the action auto-paging links. Thanks... appreciate the help TML JAVA public boolean isHasColumnsAndItems() { return Math.min(tableColumns, itemsPerPage) > 0; } public boolean isAtRowEnd() { return ((index - cursor) % Math.min(tableColumns, itemsPerPage)) == 0; } public String getTrTags() { return ""; }
RE: outputting expression logic
Rob, Thanks for the constructive criticism. I will give this a whirl... like what I see... I am all for good form... and one of the nice things I am excited about T5 is that it promotes a ton of loose options for achieving good form. Appreciate the help and will let you know how I make out. - cheers KEN
Re: outputting expression logic
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: .java: @Property private int index; @Property private Object currentObject; public String getTrTags() { return ""; } 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... > > value="ognl:currentObject" index="ognl:index"> > > > > > raw="true"/> > > > > 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
Re: outputting expression logic
Wow, I wouldn't want to have to maintain an app full of tml files like that. I think you're not realizing yet how much more maintainable a good clean T5-style template really is. Java is so much more expressive for logic anyway. Bob Harner On Sep 17, 2011 5:20 PM, "Ken in Nashua" wrote: > > > > > > > > > > Thanks Thiago... I didn't think it unreasonable to have fundamental ops to take code like this... > > > > > > > > > > > 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 > > >
RE: outputting expression logic
Well I am not sure what to do... I don't want to drag multiple variables and logic and get those all rigged up in my page from the component just to do a single method... or two that take multiple parameters and reference multiple variables from within. It would be nice if we had an arithmetic operator kinda like "prop:" "math:" and maybe a function operator "func:" so i can keep all my component logic self contained. Any last ditch efforts to accommodate my dreams ? Ken > To: users@tapestry.apache.org; kcola...@live.com > Subject: Re: outputting expression logic > Date: Fri, 16 Sep 2011 07:48:41 -0300 > From: thiag...@gmail.com > > On Thu, 15 Sep 2011 23:53:18 -0300, Ken in Nashua > wrote: > > > I guess I am asking for an ognl engine... to do these calculations > > within tml files > > Are you really sure you want to have logic in your template and make it > look like JSP (which sucks), as Steve said? Mixing output generation and > logic is a recipe for confusion. When I started working with T5 I've also > missed OGNL, but later I got used to it and I use almost just property > expressions exclusively since then. > > ChenilleKit has an OGNL binding. > > > be nice if there were an expression operator in T5 to do these... > > That's not going to happen. This was dropped from T5 on purpose. > > > guess I will have to make a java method... > > This is the canonical approach. Logic belongs in Java classes. > > It does seem to me that you're trying to write T5 thinking in T4 terms. I > don't advise you to do that. The main concepts are mostly the same, but > the implementation is very, very different. > > -- > 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
RE: outputting expression logic
Thanks Thiago... logically it makes sense... just trying to avoid code bloat in the java module and going for the short cut drill into the object at the tml level. I do think moving the logic to java will prompt the developer to make things more reasonably understandable by working in realistic operations that will be understood better in the tml file... anyway... getting closer... gallery widget pending ciao > To: users@tapestry.apache.org; kcola...@live.com > Subject: Re: outputting expression logic > Date: Fri, 16 Sep 2011 07:48:41 -0300 > From: thiag...@gmail.com > > On Thu, 15 Sep 2011 23:53:18 -0300, Ken in Nashua > wrote: > > > I guess I am asking for an ognl engine... to do these calculations > > within tml files > > Are you really sure you want to have logic in your template and make it > look like JSP (which sucks), as Steve said? Mixing output generation and > logic is a recipe for confusion. When I started working with T5 I've also > missed OGNL, but later I got used to it and I use almost just property > expressions exclusively since then. > > ChenilleKit has an OGNL binding. > > > be nice if there were an expression operator in T5 to do these... > > That's not going to happen. This was dropped from T5 on purpose. > > > guess I will have to make a java method... > > This is the canonical approach. Logic belongs in Java classes. > > It does seem to me that you're trying to write T5 thinking in T4 terms. I > don't advise you to do that. The main concepts are mostly the same, but > the implementation is very, very different. > > -- > 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
Re: outputting expression logic
On Thu, 15 Sep 2011 23:53:18 -0300, Ken in Nashua wrote: I guess I am asking for an ognl engine... to do these calculations within tml files Are you really sure you want to have logic in your template and make it look like JSP (which sucks), as Steve said? Mixing output generation and logic is a recipe for confusion. When I started working with T5 I've also missed OGNL, but later I got used to it and I use almost just property expressions exclusively since then. ChenilleKit has an OGNL binding. be nice if there were an expression operator in T5 to do these... That's not going to happen. This was dropped from T5 on purpose. guess I will have to make a java method... This is the canonical approach. Logic belongs in Java classes. It does seem to me that you're trying to write T5 thinking in T4 terms. I don't advise you to do that. The main concepts are mostly the same, but the implementation is very, very different. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: outputting expression logic
Some call it clutter, I call it refactor safe! A problem I often saw with T4 is people tended to push as much logic as they could into the .tml - with the pain they encountered afterwards, I wondered why they didn't just stick to JSPs?! And does nothing more than ${cursor} + 1 as all outputRaw does is evaluate your expression and write out as raw, un-escaped HTML. Steve. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
RE: outputting expression logic
So far I have to clutter up my component with this.. wish I could just do it in the tml like ognl as-is in t-4.1.2 not interested in chenelle @Persist("session") @Property private int cursorStartPosition; @Persist("session") @Property private int cursorEndPosition; @Persist("session") @Property private int collectionSize; @BeginRender public void beginRender() { itemsPerPage = 50; tableColumns = 3; /** * auto paging metrics */ cursorStartPosition = cursor + 1; cursorEndPosition = cursor + (collection == null ? 0 : java.lang.Math.min(collection.size(), itemsPerPage)); collectionSize = (collection == null ? 0 : collection.size()); } kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: RE: outputting expression logic Date: Thu, 15 Sep 2011 22:53:18 -0400 I guess I am asking for an ognl engine... to do these calculations within tml files be nice if there were an expression operator in T5 to do these... guess I will have to make a java method... any solutions or canonical approach are appreciated... kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: RE: outputting expression logic Date: Thu, 15 Sep 2011 22:47:03 -0400 this seems to produce "0 + 1" instead of the desired "1" all i am trying to do is have the arithmetic performed before the output thanks kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: outputting expression logic Date: Thu, 15 Sep 2011 22:00:46 -0400 Hi All, I have this expression in a component definition... ${cursor} + 1 For my case cursor is initially 0 After render... I view page source and I see the following... 0 + 1 when what I actually wanted to see is... the sum of the expression and the value rendered... 1 Any tips on how i can do this ? Is there an arithmetic or expression operator that I can prefix before my "${cursor} + 1" ? Thanks
RE: outputting expression logic
I guess I am asking for an ognl engine... to do these calculations within tml files be nice if there were an expression operator in T5 to do these... guess I will have to make a java method... any solutions or canonical approach are appreciated... kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: RE: outputting expression logic Date: Thu, 15 Sep 2011 22:47:03 -0400 this seems to produce "0 + 1" instead of the desired "1" all i am trying to do is have the arithmetic performed before the output thanks kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: outputting expression logic Date: Thu, 15 Sep 2011 22:00:46 -0400 Hi All, I have this expression in a component definition... ${cursor} + 1 For my case cursor is initially 0 After render... I view page source and I see the following... 0 + 1 when what I actually wanted to see is... the sum of the expression and the value rendered... 1 Any tips on how i can do this ? Is there an arithmetic or expression operator that I can prefix before my "${cursor} + 1" ? Thanks
RE: outputting expression logic
this seems to produce "0 + 1" instead of the desired "1" all i am trying to do is have the arithmetic performed before the output thanks kcola...@live.com From: kcola...@live.com To: users@tapestry.apache.org Subject: outputting expression logic Date: Thu, 15 Sep 2011 22:00:46 -0400 Hi All, I have this expression in a component definition... ${cursor} + 1 For my case cursor is initially 0 After render... I view page source and I see the following... 0 + 1 when what I actually wanted to see is... the sum of the expression and the value rendered... 1 Any tips on how i can do this ? Is there an arithmetic or expression operator that I can prefix before my "${cursor} + 1" ? Thanks
Re: outputting expression logic
Hi Tapestry property expressions do not support arithmetic operations. See http://tapestry.apache.org/property-expressions.html for complete list of operations supported On Fri, Sep 16, 2011 at 7:30 AM, Ken in Nashua wrote: > > Hi All, > > I have this expression in a component definition... > > ${cursor} + 1 > > For my case cursor is initially 0 > > After render... I view page source and I see the following... > > 0 + 1 > > when what I actually wanted to see is... the sum of the expression and the > value rendered... > > 1 > > Any tips on how i can do this ? Is there an arithmetic or expression operator > that I can prefix before my "${cursor} + 1" ? > > Thanks > -- Regards Taha Hafeez Siddiqi (tawus) http://tawus.wordpress.com - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org