• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • scripts
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
 - 
  • CacheControlFilter
  • CharacterEncodingFilter
  • FacesExceptionFilter
  • GzipResponseFilter
  • HttpFilter

Available since OmniFaces 1.0

The FacesExceptionFilter will solve 2 problems with exceptions thrown in JSF methods.

  1. Mojarra's FacesFileNotFoundException needs to be interpreted as 404.
  2. Root cause needs to be unwrapped from FacesException and ELException to utilize standard Servlet API error page handling.

Noted should be that this filter won't run on exceptions thrown during ajax requests. To handle them using web.xml configured error pages, use FullAjaxExceptionHandler.

Installation

To get it to run, map this filter on the <servlet-name> of the FacesServlet in the same web.xml.

<filter>
    <filter-name>facesExceptionFilter</filter-name>
    <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>facesExceptionFilter</filter-name>
    <servlet-name>facesServlet</servlet-name>
</filter-mapping>

Configuration

By default only FacesException and ELException are unwrapped. You can supply a context parameter "org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP" to specify additional exception types to unwrap. The context parameter value must be a commaseparated string of fully qualified names of additional exception types.

<context-param>
    <param-name>org.omnifaces.EXCEPTION_TYPES_TO_UNWRAP</param-name>
    <param-value>javax.ejb.EJBException,javax.persistence.RollbackException</param-value>
</context-param>

This context parameter will also be read and used by FullAjaxExceptionHandler.

Demo

The FacesExceptionFilter is also configured on this showcase application. To see the proper handling of 404 yourself, try entering a random URL matching the *.xhtml URL pattern of the FacesServlet on this showcase web application. For example, thisdoesnotexist.xhtml. To see the proper handling of FacesException yourself, invoke the "normal request" buttons on the FullAjaxExceptionHandler showcase page. Without the filter, the RuntimeException and SQLException would end up in an generic HTTP 500 error page instead of the one specific to the exception.