You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jeffrey ai <jf...@gmail.com> on 2007/11/19 21:15:47 UTC

How to initialize a session variable in a page render request?

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.


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


Re: How to initialize a session variable in a page render request?

Posted by jeffrey ai <jf...@gmail.com>.
Thanks Lasitha.
I did a search later of all guide. It's only mentioned in the page
navigation guide.
I still think it should be mentioned in the life cycle guide.
I think that's the first place for developers to look for that information.

Cheers,
Jeffrey Ai

lasitha wrote:
> 
> On Nov 20, 2007 4:54 AM, jeffrey ai <jf...@gmail.com> wrote:
>>
>> 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
> 
> Is it not sufficient to have it here?:
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html
> Perhaps a reference from lifecycle to pageNavigation?
> 
> Cheers, lasitha.
> 
> ---------------------------------------------------------------------
> 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/T5%3A-How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13861368
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: How to initialize a session variable in a page render request?

Posted by lasitha <la...@gmail.com>.
On Nov 20, 2007 4:54 AM, jeffrey ai <jf...@gmail.com> wrote:
>
> 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

Is it not sufficient to have it here?:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html
Perhaps a reference from lifecycle to pageNavigation?

Cheers, lasitha.

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


Re: How to initialize a session variable in a page render request?

Posted by jeffrey ai <jf...@gmail.com>.
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 <jf...@gmail.com> 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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> --
> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to initialize a session variable in a page render request?

Posted by Josh Canfield <jo...@thedailytube.com>.
>
> 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 <jf...@gmail.com> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: How to initialize a session variable in a page render request?

Posted by jeffrey ai <jf...@gmail.com>.
No Carlos. Actually, you reminded me. The original message title is without
T5. I added it later after reading your message.

Thanks,
Jeffrey Ai


carlos f wrote:
> 
> 
> 
> carlos f wrote:
>> 
>> If you are using tap 4.x . . .
>> 
> 
> Maybe if I looked at the subject of the original message I would have seen
> the "T5" staring at me ;)
> 
> Carlos
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13860937
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: How to initialize a session variable in a page render request?

Posted by carlos f <ca...@yahoo.com>.


carlos f wrote:
> 
> If you are using tap 4.x . . .
> 

Maybe if I looked at the subject of the original message I would have seen
the "T5" staring at me ;)

Carlos
-- 
View this message in context: http://www.nabble.com/T5%3A-How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13859449
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: How to initialize a session variable in a page render request?

Posted by carlos f <ca...@yahoo.com>.


jeffrey ai 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.
> 

Jeffrey,

I am not sure about the particulars of your situation.  If you are using tap
4.x, you might want to look into the InitialValue/Bean
annotation/specification element or use an application state object to
configure and manage your session scoped object.

Carlos
-- 
View this message in context: http://www.nabble.com/How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13846518
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: How to initialize a session variable in a page render request?

Posted by jeffrey ai <jf...@gmail.com>.
Well, in the life cycle guide, it is said it could be used for
initializations or caching.
Actually, I have confirmed it could do that, but just it doesn't work to
retrieve and mutate persistent variables.

Cheers,
Jeffrey Ai


Michael Courcy wrote:
> 
> I may be wrong as I'm a tapestry newbie, but pageAttached is something 
> related to the compilation and pooling of the page template. Thus it 
> should not deal with session buisness.
> 
> jeffrey ai a écrit :
>> 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
>>   
> 
> 
> -- 
> Michael Courcy
> http://courcy.blogspot.com
> 
> 
> ---------------------------------------------------------------------
> 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/T5%3A-How-to-initialize-a-session-variable-in-a-page-render-request--tf4839139.html#a13861371
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: How to initialize a session variable in a page render request?

Posted by Michael Courcy <mi...@gmail.com>.
I may be wrong as I'm a tapestry newbie, but pageAttached is something 
related to the compilation and pooling of the page template. Thus it 
should not deal with session buisness.

jeffrey ai a écrit :
> 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
>   


-- 
Michael Courcy
http://courcy.blogspot.com


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