You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by chakra <ch...@gmail.com> on 2009/09/13 12:36:59 UTC

Accessing page context from a component

Hi All,
Is there any easy way of accessing page context from within a component?

I have a page page1 containing components comp1 and comp2

I am accessing the page as http://localhost:8080/page/param1/param2

in Page class ,I can access param1 and param2 by simply writing an
onActivate method.

Is there any way of achieving the same inside comp1 and comp2 also?


Chakra
-- 
View this message in context: http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25422102.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: Accessing page context from a component

Posted by Sergey Didenko <se...@gmail.com>.
I see, we are actually talking about "state in page" vs "state in
component" approaches.

>> the component encapsulates the knowledge about specific
>> url parameters that it needs
> So given the above this appears to me to be paradoxical, if you are going to encapsulate the url parameters then you do not need to expose an external event method, something you can achieve with parameters for instance.

I mean encapsulate the component state from the page. It can save some
boilerplate code when you reuse the component on a lot of pages.

Also when the activation context is not simple it can be more clearly
expressed when spread over (some parts of ) the component tree.

My 2 cents :)

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


Re: Accessing page context from a component

Posted by Peter Stavrinides <P....@albourne.com>.
> Chakra words reminds me of the interesting idea for components to have
> their independent activation context. That page is not aware of.
I for one don't like this idea, if you consider what onActivate() is, and how the activation context is produced. Its an 'EXTERNAL event', a way of invoking and configuring a page from the URL (but particularly good for external URL's).

> the component encapsulates the knowledge about specific
> url parameters that it needs
So given the above this appears to me to be paradoxical, if you are going to encapsulate the url parameters then you do not need to expose an external event method, something you can achieve with parameters for instance. 

Parameters define the 'static structure' that making components so reusable, leaving the state to be handled by the containing page, imho this is a good design pattern, and where Tapestry is so successful as a component framework i.e.: true components that can be configured and reused without coupling to state saving logic.

> I wouldn't couple a component so tightly to a specific page. If you need to
> pass certain bits of information you can also use component parameters from
> within the page.
Exactly, and if necessary use mixins to enhance the component behavior when you encounter limitations with parameters

thats my 2 cents,
Peter

----- Original Message -----
From: "Sergey Didenko" <se...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Tuesday, 22 September, 2009 12:01:14 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: Accessing page context from a component

Chakra words reminds me of the interesting idea for components to have
their independent activation context. That page is not aware of.

In this case the component encapsulates the knowledge about specific
url parameters that it needs. And can be reused on different pages
without altering them. For example imagine a custom pager component
that needs parameter "pageNum".

I use a somewhat similar solution using @Environmental inside Mixins
that stores data in request parameters.
("?pageNum=3&anotherParam=3.333")

On Mon, Sep 14, 2009 at 8:15 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> Otho is exactly right here.  Each piece of Tapestry has its purpose, and
> pages act as a bridge between the client and the components within the page.
>
> On Mon, Sep 14, 2009 at 4:13 AM, Otho <ta...@googlemail.com> wrote:
>
>> I wouldn't couple a component so tightly to a specific page. If you need to
>> pass certain bits of information you can also use component parameters from
>> within the page.
>>

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


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


Re: Accessing page context from a component

Posted by Sergey Didenko <se...@gmail.com>.
Chakra words reminds me of the interesting idea for components to have
their independent activation context. That page is not aware of.

In this case the component encapsulates the knowledge about specific
url parameters that it needs. And can be reused on different pages
without altering them. For example imagine a custom pager component
that needs parameter "pageNum".

I use a somewhat similar solution using @Environmental inside Mixins
that stores data in request parameters.
("?pageNum=3&anotherParam=3.333")

On Mon, Sep 14, 2009 at 8:15 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> Otho is exactly right here.  Each piece of Tapestry has its purpose, and
> pages act as a bridge between the client and the components within the page.
>
> On Mon, Sep 14, 2009 at 4:13 AM, Otho <ta...@googlemail.com> wrote:
>
>> I wouldn't couple a component so tightly to a specific page. If you need to
>> pass certain bits of information you can also use component parameters from
>> within the page.
>>

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


Re: Accessing page context from a component

Posted by Howard Lewis Ship <hl...@gmail.com>.
Otho is exactly right here.  Each piece of Tapestry has its purpose, and
pages act as a bridge between the client and the components within the page.

On Mon, Sep 14, 2009 at 4:13 AM, Otho <ta...@googlemail.com> wrote:

> I wouldn't couple a component so tightly to a specific page. If you need to
> pass certain bits of information you can also use component parameters from
> within the page.
>
> 2009/9/14 chakra <ch...@gmail.com>
>
> >
> > thanks for the responses.
> > Is there any plan in future releases of tapestry, to add support for
> > onActivate method in components also,to get the page context?
> >
> > That will make life much easier.
> >
> > Chakra
> > --
> > View this message in context:
> >
> http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25433429.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
> >
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Accessing page context from a component

Posted by Otho <ta...@googlemail.com>.
I wouldn't couple a component so tightly to a specific page. If you need to
pass certain bits of information you can also use component parameters from
within the page.

2009/9/14 chakra <ch...@gmail.com>

>
> thanks for the responses.
> Is there any plan in future releases of tapestry, to add support for
> onActivate method in components also,to get the page context?
>
> That will make life much easier.
>
> Chakra
> --
> View this message in context:
> http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25433429.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: Accessing page context from a component

Posted by chakra <ch...@gmail.com>.
thanks for the responses. 
Is there any plan in future releases of tapestry, to add support for
onActivate method in components also,to get the page context?

That will make life much easier.

Chakra
-- 
View this message in context: http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25433429.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: Accessing page context from a component

Posted by Howard Lewis Ship <hl...@gmail.com>.
If the context needs to be shared, it needs to be exposed to the rest of the
environment in some way.
One option is for the page to implement an interface; components get get the
page (from ComponentResources) and cast it to the interface to obtain the
desired information.

Another option is a per-thread service that stores the data; the page
injects the service and invokes the setter method(s), the components inject
the service and invoke the getter method(s).

A third option, used when rendering, it to collect the context information
into an object stored into the Environment; components can use
@Environmental injection (a special kind of per-thread data binding) to
access the values.

On Sun, Sep 13, 2009 at 8:30 AM, ningdh <ni...@gmail.com> wrote:

> What about injecting ComponentEventLinkEncoder and Request to the component
> and call #decodePageRenderRequest(request) to get
> PageRenderRequestParameters.
> It contains the activationContext.
>
> DH
> http://www.gaonline.com.cn
>
> ----- Original Message -----
> From: "chakra"
> To: <us...@tapestry.apache.org>
> Sent: Sunday, September 13, 2009 6:36 PM
> Subject: Accessing page context from a component
>
>
> >
> > Hi All,
> > Is there any easy way of accessing page context from within a component?
> >
> > I have a page page1 containing components comp1 and comp2
> >
> > I am accessing the page as http://localhost:8080/page/param1/param2
> >
> > in Page class ,I can access param1 and param2 by simply writing an
> > onActivate method.
> >
> > Is there any way of achieving the same inside comp1 and comp2 also?
> >
> >
> > Chakra
> > --
> > View this message in context:
> http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25422102.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
> >
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Accessing page context from a component

Posted by ningdh <ni...@gmail.com>.
What about injecting ComponentEventLinkEncoder and Request to the component and call #decodePageRenderRequest(request) to get PageRenderRequestParameters.
It contains the activationContext.

DH
http://www.gaonline.com.cn

----- Original Message ----- 
From: "chakra" 
To: <us...@tapestry.apache.org>
Sent: Sunday, September 13, 2009 6:36 PM
Subject: Accessing page context from a component


> 
> Hi All,
> Is there any easy way of accessing page context from within a component?
> 
> I have a page page1 containing components comp1 and comp2
> 
> I am accessing the page as http://localhost:8080/page/param1/param2
> 
> in Page class ,I can access param1 and param2 by simply writing an
> onActivate method.
> 
> Is there any way of achieving the same inside comp1 and comp2 also?
> 
> 
> Chakra
> -- 
> View this message in context: http://www.nabble.com/Accessing-page-context-from-a-component-tp25422102p25422102.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
> 
>