tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Zeigler <robe...@scazdl.org>
Subject Re: Component equivalent of Page onActivate()
Date Sat, 04 Apr 2009 17:34:42 GMT
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():


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

View raw message