You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Neo Anderson <ja...@yahoo.co.uk> on 2009/06/20 19:24:53 UTC

checking userExists problem

I encounter a problem that I would like to check if user has alredy login or
not. if a user has login, then they are allowed to add product to the
shopping basket; if not, then redirect them to the login page. 

I use userExists property (private boolean userExists) to check whether user
has already login

ProductDetail.java

@SessionState;
private User user;
private boolean userExists;
...
    void onSelectedFromAddtobasket(){
        if(userExists){
            ...// add product to baseket
            page = index;
        }else{
            page = login;
        }
    }

    public boolean getUserExists(){
        return userExists;
    }

And in the Login.java

@SessionState
private User user;
...
	Object onSubmitFromLogin(){
    		if(!auth.authenticate(new User(this.account, this.password))){
 			return login;// fail to login
		}else{
			// successfully login and put user into session
			user = auth.getUser();			
			return index;
                }
        }

However, it looks like in the ProductDetail.java, the userExists value is
always false even if user has login. 

Is this the right way to check if user has login? or what would be the right
way to do it?

Thank you
-- 
View this message in context: http://n2.nabble.com/checking-userExists-problem-tp3125532p3125532.html
Sent from the Tapestry Users 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: checking userExists problem

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 20 Jun 2009 14:24:53 -0300, Neo Anderson  
<ja...@yahoo.co.uk> escreveu:

> @SessionState;
> private User user;
> private boolean userExists;

Try @SessionState(create=false) and then check if the user field is set or  
not.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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