You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by kartweel <rh...@exemail.com.au> on 2009/04/03 11:49:19 UTC

Component equivalent of Page onActivate()

Hi Everyone,

This may be simple, but I can't seem to figure it out.

A page will initialize on an action request with the onActivate() method.
But I can't figure out how to get a component to initialize on an action
request. I know we can use @SetupRender, etc, but this is no good for an
Ajax response from an embedded component because @SetupRender is never
called...

To illustrate initially I had

Page -> Subcomponent

Where the subcomponent is used to return an ajax response. All
initialization is done in the page and then parameters bound to the
component. I have not used any @Persist

I then split it up to

Page -> Component -> SubComponent

Where initialization needs to be done in the component (The page is very
simple). Because onActivate() doesn't work in the component, I simply used
onActivate() to populate some properties, then bound those to the component.
Just a simple way of passing the activation context to the component. Hope
this makes sense.

So the component needs to fetch some data from the database to initialise,
which it does when @SetupRender is called.

The issue now comes on the action request to the subcomponent, because
@SetupRender has not been called. The onActivate() has been called in the
page and the parameters passed to the component. But the component needs to
initialise and populate some extra fields (which are then passed to the
subcomponent to render the ajax response). Even without the ajax it wouldn't
matter, because if my event handler is accessing database data, it won't be
initialised yet...

I'm sure there has got to be a simple way around this other than injecting
the component into either the page or the subcomponent and then calling an
initialize method on onActivate() (from the page) or onAction() from the
subcomponent. Is there like an initialize annotation I can use? Using the
event bubbling is no good because the subcomponent event handler is fired
first before the component event handler.

-- 
View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22865238.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: Component equivalent of Page onActivate()

Posted by kartweel <rh...@exemail.com.au>.


Geoffrey Wiseman wrote:
> 
> On Sat, Apr 4, 2009 at 11:54 AM, kartweel <rh...@exemail.com.au> wrote:
> 
>> But it doesn't work for action(event) requests. So great until you press
>> the
>> button in the form or click an action link.
>>
> 
> Ah, yes, you said that before.  Sorry.  I've got no help for you, then.
> 
>   - Geoffrey
> 
> 

Thanks anyway!. At least I know it isn't just me missing something obvious
:).
-- 
View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22888757.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: Component equivalent of Page onActivate()

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Sat, Apr 4, 2009 at 11:54 AM, kartweel <rh...@exemail.com.au> wrote:

> But it doesn't work for action(event) requests. So great until you press
> the
> button in the form or click an action link.
>

Ah, yes, you said that before.  Sorry.  I've got no help for you, then.

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Component equivalent of Page onActivate()

Posted by kartweel <rh...@exemail.com.au>.

Geoffrey Wiseman wrote:
> 
> @SetupRender?
> 

But it doesn't work for action(event) requests. So great until you press the
button in the form or click an action link.
-- 
View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22884820.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: Component equivalent of Page onActivate()

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Apr 3, 2009 at 9:04 PM, kartweel <rh...@exemail.com.au> wrote:

> Anyone else got any other suggestions? An @Initialise or @onActivate
> annotation or something would be great so we can make sure things are
> initialised on render and action requests.
>

@SetupRender?

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Component equivalent of Page onActivate()

Posted by kartweel <rh...@exemail.com.au>.

Robert Zeigler wrote:
> 
> even easier than using the flag, why not use the @Cached annotation?
> 
> @Cached //will now be evaulated once and only once per request, but  
> you can play witih that using the "watch" parameter.
> 
> 

Cheers!. Didn't think of that one. Makes it a little tidier :).
-- 
View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22888743.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: Component equivalent of Page onActivate()

Posted by Robert Zeigler <ro...@scazdl.org>.
even easier than using the flag, why not use the @Cached annotation?

@Cached //will now be evaulated once and only once per request, but  
you can play witih that using the "watch" parameter.
public void getFoo() {
   return someExpensiveOperation():
}

Robert

On Apr 3, 2009, at 4/38:04 PM , kartweel wrote:

>
> I decided the easiest way is to use a lazy initialisation approach.  
> So in all
> the getters I run an initialise() method (which has a flag to only run
> once). That way it is not up to the other components or the page to
> initialise that component, it can do it itself. A bit untidy but  
> haven't got
> any other ideas??
>
> Anyone else got any other suggestions? An @Initialise or @onActivate
> annotation or something would be great so we can make sure things are
> initialised on render and action requests.
>
>
>
> kartweel wrote:
>>
>> Hi Everyone,
>>
>> This may be simple, but I can't seem to figure it out.
>>
>> A page will initialize on an action request with the onActivate()  
>> method.
>> But I can't figure out how to get a component to initialize on an  
>> action
>> request. I know we can use @SetupRender, etc, but this is no good  
>> for an
>> Ajax response from an embedded component because @SetupRender is  
>> never
>> called...
>>
>> To illustrate initially I had
>>
>> Page -> Subcomponent
>>
>> Where the subcomponent is used to return an ajax response. All
>> initialization is done in the page and then parameters bound to the
>> component. I have not used any @Persist
>>
>> I then split it up to
>>
>> Page -> Component -> SubComponent
>>
>> Where initialization needs to be done in the component (The page is  
>> very
>> simple). Because onActivate() doesn't work in the component, I  
>> simply used
>> onActivate() to populate some properties, then bound those to the
>> component. Just a simple way of passing the activation context to the
>> component. Hope this makes sense.
>>
>> So the component needs to fetch some data from the database to  
>> initialise,
>> which it does when @SetupRender is called.
>>
>> The issue now comes on the action request to the subcomponent,  
>> because
>> @SetupRender has not been called. The onActivate() has been called  
>> in the
>> page and the parameters passed to the component. But the component  
>> needs
>> to initialise and populate some extra fields (which are then passed  
>> to the
>> subcomponent to render the ajax response). Even without the ajax it
>> wouldn't matter, because if my event handler is accessing database  
>> data,
>> it won't be initialised yet...
>>
>> I'm sure there has got to be a simple way around this other than  
>> injecting
>> the component into either the page or the subcomponent and then  
>> calling an
>> initialize method on onActivate() (from the page) or onAction()  
>> from the
>> subcomponent. Is there like an initialize annotation I can use?  
>> Using the
>> event bubbling is no good because the subcomponent event handler is  
>> fired
>> first before the component event handler.
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22878887.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


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


Re: Component equivalent of Page onActivate()

Posted by kartweel <rh...@exemail.com.au>.
I decided the easiest way is to use a lazy initialisation approach. So in all
the getters I run an initialise() method (which has a flag to only run
once). That way it is not up to the other components or the page to
initialise that component, it can do it itself. A bit untidy but haven't got
any other ideas??

Anyone else got any other suggestions? An @Initialise or @onActivate
annotation or something would be great so we can make sure things are
initialised on render and action requests.



kartweel wrote:
> 
> Hi Everyone,
> 
> This may be simple, but I can't seem to figure it out.
> 
> A page will initialize on an action request with the onActivate() method.
> But I can't figure out how to get a component to initialize on an action
> request. I know we can use @SetupRender, etc, but this is no good for an
> Ajax response from an embedded component because @SetupRender is never
> called...
> 
> To illustrate initially I had
> 
> Page -> Subcomponent
> 
> Where the subcomponent is used to return an ajax response. All
> initialization is done in the page and then parameters bound to the
> component. I have not used any @Persist
> 
> I then split it up to
> 
> Page -> Component -> SubComponent
> 
> Where initialization needs to be done in the component (The page is very
> simple). Because onActivate() doesn't work in the component, I simply used
> onActivate() to populate some properties, then bound those to the
> component. Just a simple way of passing the activation context to the
> component. Hope this makes sense.
> 
> So the component needs to fetch some data from the database to initialise,
> which it does when @SetupRender is called.
> 
> The issue now comes on the action request to the subcomponent, because
> @SetupRender has not been called. The onActivate() has been called in the
> page and the parameters passed to the component. But the component needs
> to initialise and populate some extra fields (which are then passed to the
> subcomponent to render the ajax response). Even without the ajax it
> wouldn't matter, because if my event handler is accessing database data,
> it won't be initialised yet...
> 
> I'm sure there has got to be a simple way around this other than injecting
> the component into either the page or the subcomponent and then calling an
> initialize method on onActivate() (from the page) or onAction() from the
> subcomponent. Is there like an initialize annotation I can use? Using the
> event bubbling is no good because the subcomponent event handler is fired
> first before the component event handler.
> 
> 

-- 
View this message in context: http://www.nabble.com/Component-equivalent-of-Page-onActivate%28%29-tp22865238p22878887.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