Thanks, Josh. onActivate() solve the problem. I thought this method only get called for an action request, not for a page render request. Apparently, I am wrong. I think it should be documented at the following "Page Lifecycle" guide. http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifecycle.html
Cheers, Jeffrey Josh Canfield-2 wrote: > >> >> I am looking for the best way to initialize a session variable(@Persist) >> in >> a page render request once, so I could access it in the next action >> request. >> >> > I can't tell you why pageAttached doesn't work (haven't tried it) but you > can use onActivate, or if it's for a form onPrepare. > > Josh > > On Nov 19, 2007 12:15 PM, jeffrey ai <[EMAIL PROTECTED]> wrote: > >> >> Hi Folks, >> >> I am looking for the best way to initialize a session variable(@Persist) >> in >> a page render request once, so I could access it in the next action >> request. >> >> I tried to put the logic into "pageAttached" method like below: >> ==== >> @Persist >> private xxx myVar; >> >> @SuppressWarnings(value = "unused") >> private void pageAttached() >> { >> if (myVar == null) initializeVar(); >> } >> ==== >> >> It doesn't work as I expected. myVar is always null in "pageAttached" >> method. It seems the "pageAttached" method is not supposed to mutate a >> persistent variable. >> >> However, if I put this logic into some other place like below, it works >> fine. >> ==== >> @Persist >> private xxx myVar; >> >> public String getSomeOtherVar() >> { >> if (myVar == null) initializeVar(); >> return someOtherVar; >> } >> ==== >> >> Although it works, apparently, this is not a good place. >> Is there a better place to do session variable initialization? >> I believe it should not be put into constructor too because it will be >> viewable to other sessions. >> >> Thanks, >> Jeffrey Ai >> -- >> View this message in context: >> http://www.nabble.com/How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13844361 >> Sent from the Tapestry - User mailing list archive at >> Nabble.com<http://nabble.com/> >> . >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > -- > -- > TheDailyTube.com. Sign up and get the best new videos on the internet > delivered fresh to your inbox. > > -- View this message in context: http://www.nabble.com/T5%3A-How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13847864 Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]