20 September 2007

Step 08 org.example.TSA.value - SessionData

Step 08
SessionData
is an object to store userName and sessionExists flag between pages, so if a session doesn't exist then user will be redirected t Login page.

package org.example.TSA.value;

public class SessionData {
private String _userName;
private boolean sessionExists;

/**
* @return the sessionExists
*/
public boolean isSessionExists() {
return sessionExists;
}
/**
* @param exists the sessionExists to set
*/
public void setSessionExists(boolean exists) {
sessionExists = exists;
}
/**
* @return the userName
*/
public String getUserName() {
return _userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this._userName = userName;
}
}

Step 08 , org.example.TSA.pages.spages - LoginProtected

Step 08
Base (super) page class for pages which require checking whether user has logged in or not.


package org.example.TSA.pages.spages;


import org.apache.tapestry.annotations.ApplicationState;
import org.example.TSA.value.SessionData;
public abstract class LoginProtected {
@ApplicationState
private SessionData _session;

Object onActivate() {
if(!_session.isSessionExists()){
return "Login";
}
return null;
}

/**
* @return the _session
*/
public SessionData get_session() {
return _session;
}
}