Application State is for it.
see http://tapestry.apache.org/tapestry5/tapestry-core/guide/appstate.html
I have written some examples like this:
There are follwing page classes to be protected.
UserEdit.java
ShopSetting.java
if the session is null , above these pages won't be opened.
firstly I let all them extends AdminRootPage.java. the class is like this:
public class AdminRootPage {
@ApplicationState
private SessionData _session;
private boolean _sessionExists;
String onActivate() {
if(!_sessionExists){
return "Login";
}
return null;
}
}
The session data is a value object which you can put any fields value in it.
Usually the SessionData cotain the current user information whick like this
public class SessionData {
private String username ;
public String getUsername() {
return username;
}
public void setUsername(String name) {
this.username = name;
}
When you visit http://...../useredit , the adminRootPage.onActive() will
check the sessionData is null.
If it's null then go to page Login. the Login.java may be like this
public class Login {
.....
// the method will be execute when a submit button named 'login' on
Login.html
void onSelectedFromLogin() {
User user = _service.checkValidUser(username,password);
// init session if it's a valid user.
if (user==null) {
loginFrm.recordError(_passwordField, "Invalid user name or
password.");
}
_session.setUsername(username);
_session.setUser(user);
this.nextPage = PageConstant.SHOP_OVERVIEW;
}
....
}
After onSelectedFromLogin() is executed, the session will be initialized a
appropriated value
2007/8/22, Angelo Chen <[EMAIL PROTECTED]>:
>
>
> Hi,
>
> what is the correct way to manage sessions in T5? let's say, user has to
> login before it can go to other pages, how other pages check if a request
> is
> from a logined user or not? Thanks.
>
> A.C.
> --
> View this message in context:
> http://www.nabble.com/T5%3ALogin-and-session-tf4312177.html#a12276631
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>