You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by karthi <ra...@snovabits.net> on 2012/03/05 13:54:55 UTC

Issues in saving values in cookies

Hi,

   I have a tml page called portfolio.tml and in corresponding java
portfollio page I have written this following to save the values in cookies

public class Portfolio {

@org.apache.tapestry5.ioc.annotations.Inject
private Cookies cookies;

public Portfolio() {
		cookies.writeCookieValue("isUserLogin", "True");
		cookies.writeCookieValue("userId", uId);
         }

}

With this cookies set value I have used this userid and isuserlogin in other
pages to check whether the user is logged in or not and to pass this saved
userid to other transactions like below

if(null != cookies.readCookieValue("userId")) {
          // processing
}

Most of the times the values are not get saved in cookies part in my browser
(I checked under cookies in browser), this cookies.readCookieValue("userId")
returns null value, but sometimes this returns expected value (Values are
there under cookies in ma browser) and working fine.

I don't know where am making mistake in the code, Can anyone point me in the
right direction? 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Issues-in-saving-values-in-cookies-tp5537459p5537459.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: Issues in saving values in cookies

Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
The lifecycle of pages, components & mixins are maintained by Tapestry. That is why it provides you with these render phases hooks.

regards
Taha

On Mar 6, 2012, at 10:54 AM, karthi wrote:

> Thank you for your reply onActivate() method solves my problem, However
> constructor is used to prepare the variables that are required by the class
> i.e., for initialization purposes right? then what is wrong with that
> constructor, Why the cookies are not get initialized inside constructor?
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Issues-in-saving-values-in-cookies-tp5537459p5539937.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


Re: Issues in saving values in cookies

Posted by karthi <ra...@snovabits.net>.
Thank you for your reply onActivate() method solves my problem, However
constructor is used to prepare the variables that are required by the class
i.e., for initialization purposes right? then what is wrong with that
constructor, Why the cookies are not get initialized inside constructor?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Issues-in-saving-values-in-cookies-tp5537459p5539937.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: Issues in saving values in cookies

Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
Never use a page constructor for initialization . Use onActivate() 

Sent from my iPhone

On Mar 5, 2012, at 6:24 PM, karthi <ra...@snovabits.net> wrote:

> Hi,
> 
>   I have a tml page called portfolio.tml and in corresponding java
> portfollio page I have written this following to save the values in cookies
> 
> public class Portfolio {
> 
> @org.apache.tapestry5.ioc.annotations.Inject
> private Cookies cookies;
> 
> public Portfolio() {
>        cookies.writeCookieValue("isUserLogin", "True");
>        cookies.writeCookieValue("userId", uId);
>         }
> 
> }
> 
> With this cookies set value I have used this userid and isuserlogin in other
> pages to check whether the user is logged in or not and to pass this saved
> userid to other transactions like below
> 
> if(null != cookies.readCookieValue("userId")) {
>          // processing
> }
> 
> Most of the times the values are not get saved in cookies part in my browser
> (I checked under cookies in browser), this cookies.readCookieValue("userId")
> returns null value, but sometimes this returns expected value (Values are
> there under cookies in ma browser) and working fine.
> 
> I don't know where am making mistake in the code, Can anyone point me in the
> right direction? 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Issues-in-saving-values-in-cookies-tp5537459p5537459.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