4

How can I catch a

com.sun.faces.context.FacesFileNotFoundException

in a Java EE web application?

I tried it with adding the following lines in my web.xml file but I was not successful:

  ...
  <error-page>
    <error-code>404</error-code>
    <location>/404.jsf</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/404.jsf</location>
  </error-page>
  <error-page>
    <exception-type>FacesFileNotFoundException</exception-type>
    <location>/404.jsf</location>
  </error-page>
  <error-page>
    <exception-type>FileNotFoundException</exception-type>
    <location>/404.jsf</location>
  </error-page>
  <error-page>
    <exception-type>FailingHttpStatusCodeException</exception-type>
    <location>/404.jsf</location>
  </error-page>
</web-app>
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Benny Code
  • 51,456
  • 28
  • 233
  • 198

1 Answers1

7

You need to specify the FQN (Full Qualified Name), not just the N as exception type.

<exception-type>com.sun.faces.context.FacesFileNotFoundException</exception-type>

Alternatively, if you already happen to use OmniFaces, register its FacesExceptionFilter and then the FacesFileNotFoundException will be handled as 404.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • What exactly happens instead? – BalusC Mar 07 '11 at 15:44
  • The output is the following: 1. StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception com.sun.faces.context.FacesFileNotFoundException 2. PWC1231: Servlet.service() for servlet Faces Servlet threw exception 3. org.apache.catalina.core.StandardHostValve@16933312: Exception Processing ErrorPage[exceptionType=com.sun.faces.context.FacesFileNotFoundException, location=/404.jsf] javax.servlet.ServletException: Context is already active at javax.faces.webapp.FacesServlet.service(FacesServlet.java:422) – Benny Code Mar 08 '11 at 01:16
  • 2
    Make it a plain JSP/HTML page instead and retry. – BalusC Mar 08 '11 at 02:41
  • THIS WORKS!!! I think it is because I want to use a JSF for a JSF exception which is not possible because JSF already crashed (due to the exception)!? THANK YOU! – Benny Code Mar 08 '11 at 17:05