users@glassfish.java.net

Re: ViewExpiredException not caught by handler

From: <glassfish_at_javadesktop.org>
Date: Fri, 08 Aug 2008 00:39:36 PDT

Hello There!

This particular exception (ViewExpiredException - viewID could not be restored) drove me crazy for days! It was a minor annoyance but still clogged my server logs

I could not find any answers on the web, so I came up with one of my own.

First you need to implement a PhaseListener like so:

package jsf;
public class MyListener implements PhaseListener {

public void beforePhase(PhaseEvent e) {
  if (e.getPhaseId() == PhaseId.RESTORE_VIEW) {
    if (e.getFacesContext().getExternalContext().getSession(false) == null) {
      e.getFacesContext().getApplication().getNavigationHandler().handleNavigation(
          e.getFacesContext(), "", "sessionExpired");
      }
   }
}

This little class will listen to the restore view phase. If a session is not found, then it redirects to the sessionExpired navigation rule defined in faces-config.xml

You have to edit your faces config file so the listener would be loaded and the navigation rule exists

 <lifecycle>
  <phase-listener>jsf.MyListener</phase-listener>
 </lifecycle>

 <navigation-rule>
  <navigation-case>
   <from-outcome>sessionExpired</from-outcome>
   <to-view-id>/sessionexpired.jsf</to-view-id>
  </navigation-case>
 </navigation-rule>


Good luck!
[Message sent by forum member 'diablillo' (diablillo)]

http://forums.java.net/jive/thread.jspa?messageID=292251