You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bryan Lewis <jb...@gmail.com> on 2009/04/20 04:18:10 UTC

once-only onActivate method

I need a method that will get called exactly once when a page is first
invoked, and not again when a form in the page is submitted.  In Tapestry 4
the activateExternalPage() method was good for that.  I don't think the new
onActivate() method is a replacement, nor is the SetupRender-annotated
method.  For example, they get called when an autocomplete textfield is used
in mid-form.  How do I do this in Tap 5?  (My intent is to clear any stale
changes in my Cayenne DataContext.)

Thanks.

Re: once-only onActivate method

Posted by Bryan Lewis <jb...@gmail.com>.
Thanks for the tips.  As Ville said, PageLoaded didn't work out because it's
called only when the page is created and added to the pool, not on every
invocation.

The form events were promising... onPrepareForRender() is called exactly
once per page.  The method can be tucked away in our base Page class so that
we wouldn't have to think about it most of the time, and it gets called for
any page containing a form.  However, we have a few pages where we update
our database objects without a form, for example with a button-styled link
or in a page's SetupRender method.

I have a working solution now, although it's a bit more plumbing-ish than
I'd like. It's at the end of AppModule's TimingFilter.  (Yeah, I know, I'm
turning the TimingFilter into a kitchen sink.  I'll clean it up if it
continues to work well.)  After a real page request is handled (not a
request for a static resource like an image), I clear my DataContext.

Thanks!


On Mon, Apr 20, 2009 at 2:08 PM, Ville Virtanen <vi...@cerion.fi>wrote:

>
> This probably is NOT the solution, as this method gets executed only once
> when the page is loaded and added to the pool.
>
> Multiple users and hundreds of requests can be served with only one call to
> PageLoaded, if I understand it correctly.
>
> The pageAttached and pageDetached events occur when the page is fetched
> from
> the pool (attach) and returned back (detach). This occurs once per request.
>
> The best solution that I can come up is to use additional context parameter
> to simulate the activateExternalPage(), so when you use page link or
> similar
> you can "notify" the page correctly.
>
> I mean
>
> onActivate(Long key, boolean fromAnotherPage) {
>  //Do activateExternalPage() stuff
> }
>
> onActivate(Long key){
>  if(noInitializationYetDone){
>    //do normal initialization
>  }
> }
>
> onPassivate(){
>  return key;
> }
>
> This way the normal page flow does the normal initialization on form
> postbacks etc, and the special initialization can be done if the link that
> directs to the page contains the magic boolean in the context.
>
> However, this should be avoided by design, so that page can initialize
> itself correctly without stale checks imho, so no data in session etc. (I
> don't know how Cayenne works so this might not apply, but I've noticed that
> this is best practise for our apps w/ hibernate.)
>
>  - Ville
>
>
> JoelGrrrr wrote:
> >
> > This might help... PageLoaded ...
> >
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/PageLoaded.html
> >
> >
> >
> > -----Original Message-----
> > From: Bryan Lewis <jb...@gmail.com>
> > Reply-To: Tapestry users <us...@tapestry.apache.org>
> > To: users@tapestry.apache.org
> > Subject: once-only onActivate method
> > Date: Sun, 19 Apr 2009 22:18:10 -0400
> >
> > I need a method that will get called exactly once when a page is first
> > invoked, and not again when a form in the page is submitted.  In Tapestry
> > 4
> > the activateExternalPage() method was good for that.  I don't think the
> > new
> > onActivate() method is a replacement, nor is the SetupRender-annotated
> > method.  For example, they get called when an autocomplete textfield is
> > used
> > in mid-form.  How do I do this in Tap 5?  (My intent is to clear any
> stale
> > changes in my Cayenne DataContext.)
> >
> > Thanks.
> >
> > --
> > Joel Halbert
> > 020 3051 8637
> > 075 2501 0825
> > joel@storequery.com
> > www.storequery.com
> > SU3 Analytics Ltd, The Print House, 18 Ashwin St, London E8 3DL.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/once-only-onActivate-method-tp23129460p23141937.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: once-only onActivate method

Posted by Ville Virtanen <vi...@cerion.fi>.
This probably is NOT the solution, as this method gets executed only once
when the page is loaded and added to the pool.

Multiple users and hundreds of requests can be served with only one call to
PageLoaded, if I understand it correctly.

The pageAttached and pageDetached events occur when the page is fetched from
the pool (attach) and returned back (detach). This occurs once per request.

The best solution that I can come up is to use additional context parameter
to simulate the activateExternalPage(), so when you use page link or similar
you can "notify" the page correctly.

I mean

onActivate(Long key, boolean fromAnotherPage) {
  //Do activateExternalPage() stuff
}

onActivate(Long key){
  if(noInitializationYetDone){
    //do normal initialization
  }
}

onPassivate(){
  return key;
}

This way the normal page flow does the normal initialization on form
postbacks etc, and the special initialization can be done if the link that
directs to the page contains the magic boolean in the context.

However, this should be avoided by design, so that page can initialize
itself correctly without stale checks imho, so no data in session etc. (I
don't know how Cayenne works so this might not apply, but I've noticed that
this is best practise for our apps w/ hibernate.)

 - Ville


JoelGrrrr wrote:
> 
> This might help... PageLoaded ... 
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/PageLoaded.html
> 
> 
> 
> -----Original Message-----
> From: Bryan Lewis <jb...@gmail.com>
> Reply-To: Tapestry users <us...@tapestry.apache.org>
> To: users@tapestry.apache.org
> Subject: once-only onActivate method
> Date: Sun, 19 Apr 2009 22:18:10 -0400
> 
> I need a method that will get called exactly once when a page is first
> invoked, and not again when a form in the page is submitted.  In Tapestry
> 4
> the activateExternalPage() method was good for that.  I don't think the
> new
> onActivate() method is a replacement, nor is the SetupRender-annotated
> method.  For example, they get called when an autocomplete textfield is
> used
> in mid-form.  How do I do this in Tap 5?  (My intent is to clear any stale
> changes in my Cayenne DataContext.)
> 
> Thanks.
> 
> -- 
> Joel Halbert
> 020 3051 8637
> 075 2501 0825
> joel@storequery.com
> www.storequery.com
> SU3 Analytics Ltd, The Print House, 18 Ashwin St, London E8 3DL.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/once-only-onActivate-method-tp23129460p23141937.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: once-only onActivate method

Posted by Joel Halbert <jo...@su3analytics.com>.
This might help... PageLoaded ... 
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/PageLoaded.html



-----Original Message-----
From: Bryan Lewis <jb...@gmail.com>
Reply-To: Tapestry users <us...@tapestry.apache.org>
To: users@tapestry.apache.org
Subject: once-only onActivate method
Date: Sun, 19 Apr 2009 22:18:10 -0400

I need a method that will get called exactly once when a page is first
invoked, and not again when a form in the page is submitted.  In Tapestry 4
the activateExternalPage() method was good for that.  I don't think the new
onActivate() method is a replacement, nor is the SetupRender-annotated
method.  For example, they get called when an autocomplete textfield is used
in mid-form.  How do I do this in Tap 5?  (My intent is to clear any stale
changes in my Cayenne DataContext.)

Thanks.

-- 
Joel Halbert
020 3051 8637
075 2501 0825
joel@storequery.com
www.storequery.com
SU3 Analytics Ltd, The Print House, 18 Ashwin St, London E8 3DL.


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


Re: once-only onActivate method

Posted by Robert Zeigler <ro...@scazdl.org>.
Hi Bryan,

What about utilizing the form's events, prepareForRender vs.  
prepareForSubmit?
See: http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Form.html

Robert

On Apr 19, 2009, at 4/199:18 PM , Bryan Lewis wrote:

> I need a method that will get called exactly once when a page is first
> invoked, and not again when a form in the page is submitted.  In  
> Tapestry 4
> the activateExternalPage() method was good for that.  I don't think  
> the new
> onActivate() method is a replacement, nor is the SetupRender-annotated
> method.  For example, they get called when an autocomplete textfield  
> is used
> in mid-form.  How do I do this in Tap 5?  (My intent is to clear any  
> stale
> changes in my Cayenne DataContext.)
>
> Thanks.


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