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 <ville.virta...@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 <jbryanle...@gmail.com>
> > Reply-To: Tapestry users <users@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
> > j...@storequery.com
> > www.storequery.com
> > SU3 Analytics Ltd, The Print House, 18 Ashwin St, London E8 3DL.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to