Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Session time out handling through phase listener

796588Oct 30 2009 — edited Nov 2 2009
I am trying to handle session timeout using phase listener. am getting RuntimeException of FacesContext cannot be found. My code & error as follows. Pls let me know where i have gone wrong...

my phaselistener code :

public class SessionTimeoutPhaseListener implements PhaseListener{
public void beforePhase(PhaseEvent event)
{
System.out.println("Inside phase listener");
FacesContext facesCtx = event.getFacesContext();
ExternalContext extCtx = facesCtx .getExternalContext();
HttpSession session = (HttpSession)extCtx .getSession(false);
boolean newSession = (session == null) || (session.isNew());
boolean postback = !extCtx.getRequestParameterMap().isEmpty();
boolean timedout = postback && newSession;
if(timedout) {
try {
System.out.println("Inside phase listener-time out");
Application app = facesCtx.getApplication();
String url=extCtx.encodeActionURL(extCtx.getRequestContextPath()+"/jsp/NewLogin.jsp");
System.out.println("Redirect url-"+url);

extCtx.redirect(url);
facesCtx.renderResponse();


System.out.println("redirect");
facesCtx.responseComplete();
}


public void afterPhase(PhaseEvent event) { // Do nothing
}
public PhaseId getPhaseId() { return PhaseId.RESTORE_VIEW; }


}


OutPut:
Inside phase listener
Inside phase listener
Inside phase listener-time out
Redirect url-/cbscrown/jsp/NewLogin.jsp
redirect
StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Cannot find FacesContext
at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1811)
at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1628)


Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2009
Added on Oct 30 2009
5 comments
691 views