ViewExpiredException error page not shown

glassfish-4, jsf, jsf-2.2, viewexpiredexception

Solution

That's expected behaviour, if you look at sections 13.3.6.3 and 13.3.6.4 of the JSF-2.2 spec, at least if you have

<context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>
  <param-value>Development</param-value>
</context-param>

in your `web.xml` (it silently ignores the error in production mode). The JSF client-side code sends an AJAX request when you click that button and receives

<error>
    <error-name>...</error-name>
    <error-message>...</error-message>
</error>

with your `ViewExpiredException` in the response. The client-side code is then expected to react to that error information. Register a function with `onerror` (on the `f:ajax` tag) or `addOnError` (on the `jsf.ajax` object) to handle error yourself.

Since a lot of folks expect the server to direct the client on such an issue, omnifaces includes the FullAjaxExceptionHandler that basically resets your response and sends the error page you specified.

See also:

Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

Problem

I leave some tabs open with forms and when I press the command buttons (after some time when the session expires) I receive a java script alert saying: serverError: class javax.faces.application.ViewExpiredException viewId:/register.xhtml - View /register.xhtml could not be restored. On firefox (glassfish 4 locally) I have added : ``` <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/index.xhtml?faces-redirect=true</location> </error-page> ``` in my `web.xml` but I am not redirected to my index. Why is that ? Edit: sample button ``` <h:commandButton value="Register" action="#{userController.register}"> <f:ajax execute="@form" render="@form" /> </h:commandButton> ``` UserController is ViewScoped

Original source

Related problems