You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by stephanos2k <st...@googlemail.com> on 2011/03/21 18:27:35 UTC

Customizing the Layout Component

In my Layout I'd like to distinguish between 2 states (let's just say red or
blue). 
Those are known/set by each page individually - it inherits from BasePageRed
or BasePageBlue (which go back to BasePage where the parameter Col is
defined).

How do I 'get' the parameter value from the BasePage (class) to the Layout
(tml)?

PS: I am aware that I can set the parameter in Page.tml - but I don't want
to repeat myself in each file.

Cheers,
Stephanos

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Customizing-the-Layout-Component-tp4234938p4234938.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Customizing the Layout Component

Posted by stephanos2k <st...@googlemail.com>.
Thanks a lot for the info, Barry!
Will definitely check it out.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Customizing-the-Layout-Component-tp4234938p4258643.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Customizing the Layout Component

Posted by Barry Books <tr...@gmail.com>.
If you have a Blue/Red that inherit from BasePage I'd use a Layout Environmental. Since you have a BasePage you can create the Environmental in your BasePage class. The Red/Blue pages should be able to set the color property and then the layout component can retrieve it. That way only those 4 classes need to know about it.

I'd provide an example but I'm typing this on my phone.

See Environmental Services in the docs. If you have trouble post back and I'll post and example when I get home. I usually create a Layout Envrionmental on my projects because I think it's easier than passing parms via the template.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Customizing the Layout Component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 21 Mar 2011 15:22:30 -0300, stephanos2k  
<st...@googlemail.com> wrote:

> Thanks for the quick response!
> Hm, I didn't know that this would break the class hierarchy.

It doesn't.

> I understand the issue like this (hope it works in HTML/Mail):
> Layout.tml > Page.tml --> Result <-- Page.java < BasePageRed.java <

It's not correct. Layout is rendered inside Page, not the opposite. Layout  
is a component as any other and it's being used as part of the Page  
template.

> I am far from completely grasping what goes on when Tapestry renders,  
> but I though the tmls ('left') and classes ('right') are merged somehow.

There's no merge.

> I assumed I could tell Layout to 'expect' a Parameter coming from the  
> class side.

<t:layout parameterName="some value>...

In Layout:

@Parameter
private AnyTypeYouWant parameterName;

-- 
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Customizing the Layout Component

Posted by stephanos2k <st...@googlemail.com>.
Thanks for the quick response!
Hm, I didn't know that this would break the class hierarchy.

I understand the issue like this (hope it works in HTML/Mail):
Layout.tml > Page.tml --> Result <-- Page.java < BasePageRed.java <
BasePage.java
 [read P]                                                                  
[Set P]                  [Declare P]

I am far from completely grasping what goes on when Tapestry renders, but I
though the tmls ('left') and classes ('right') are merged somehow. 
I assumed I could tell Layout to 'expect' a Parameter coming from the class
side. 
Alternatively, setting the parameter in every Page.tml (few dozen) just
didn't seem so 'DRY'.

But your solution sounds very reasonable - I was just wondering :-)

Cheers

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Customizing-the-Layout-Component-tp4234938p4235829.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Customizing the Layout Component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 21 Mar 2011 14:27:35 -0300, stephanos2k  
<st...@googlemail.com> wrote:

> In my Layout I'd like to distinguish between 2 states (let's just say  
> red or blue). Those are known/set by each page individually - it  
> inherits from BasePageRed or BasePageBlue (which go back to BasePage  
> where the parameter Col is
> defined).
> How do I 'get' the parameter value from the BasePage (class) to the  
> Layout (tml)?
> PS: I am aware that I can set the parameter in Page.tml - but I don't  
> want to repeat myself in each file.

Abusing class hierarchy, for me, is way worse than adding a single  
parameter to a component use.
Another option (preferred) is to define an annotation and use  
ComponentResources.getPage() to get the page instance and check if that  
annotation is there or not.

-- 
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org