Exception
Solution to give better feedback to the user when an ajax request is made on a page with an expired session. The OmniFaces FullAjaxExceptionHandler catches the ViewExpiredException and handles them with error pages defined in the web.xml . In this case the user is send to an error page and given the option to return to the previous page they were working on.
The FullAjaxExceptionHandler needs to be registered by a factory in faces-config.xml :
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
The exception handler will parse the web.xml file to find the error page location of all declared exception types (in this case ViewExpiredException).
So the error page needs to be:
- added to the views
- added as an error-page to the web.xml
Example for web.xml:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/jsf/system/security/access/errorPage.xhtml</location>
</error-page>
<h:body>
<ui:composition>
<j:row id="row">
<j:slot width="12">
<p><a href="#{fn:replace(fn:replace(requestScope['javax.servlet.error.request_uri'] , '.xhtml',''),'/jsf','')}">Back to initial page.</a></p>
</j:slot>
</j:row>
</ui:composition>
</h:body>
public void throwViewExpiredException()
{
throw new javax.faces.application.ViewExpiredException("Throwing the exception for showcase purposes");
}