public class FacesExceptionFilter extends HttpFilter
The FacesExceptionFilter
will solve 2 problems with exceptions thrown in JSF methods.
FacesFileNotFoundException
needs to be interpreted as 404.
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
.
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>
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
.
FullAjaxExceptionHandler
,
HttpFilter
Constructor and Description |
---|
FacesExceptionFilter() |
Modifier and Type | Method and Description |
---|---|
void |
doFilter(HttpServletRequest request,
HttpServletResponse response,
HttpSession session,
FilterChain chain)
Filter the HTTP request.
|
void |
init()
Convenience init() method without FilterConfig parameter which will be called by init(FilterConfig).
|
destroy, doFilter, getFilterConfig, getInitParameter, getServletContext, init
public void init() throws ServletException
HttpFilter
init
in class HttpFilter
ServletException
- When filter's initialization failed.public void doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain) throws ServletException, IOException
HttpFilter
null
if there is no session.doFilter
in class HttpFilter
request
- The HTTP request.response
- The HTTP response.session
- The HTTP session, if any, else null
.chain
- The filter chain to continue.ServletException
- As wrapper exception when something fails in the request processing.IOException
- Whenever something fails at I/O level.Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
Copyright © 2012–2017 OmniFaces. All rights reserved.