1

I have a problem with the FullAjaxExceptionHandler on ajax requests using the Omnifaces.

  • Environment:
  • Tomcat 7.0.50
  • Mojarra 2.1.27
  • Omnifaces 1.7

I declared the error pages in my web.xml:

<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/error/errorPage.jsf</location>
</error-page>
<filter>
  <filter-name>facesExceptionFilter</filter-name>
  <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>facesExceptionFilter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

And I declared the exception handler on faces-config.xml

<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>

With this environment the error page is shown correctly when throw an exception on a @PostConstruct method on a non-ajax request. When I throw an exception on an ajax request, the error page is not shown, but I see this log message.

FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error/errorPage.jsf' will be shown.

After a while, I see another log message and the browser opens the "hardcoded error page".

FullAjaxExceptionHandler: Well, another exception occurred during rendering error page '/error/erroPage.jsf'. Trying to render a hardcoded error page now.
javax.faces.FacesException: org.apache.jasper.JasperException: /error/errorPage.jspx (line: 11, column: 39) Attribute "xmlns:h" must be declared for element type "html".

It seems that the JSP is trying to render the JSF page. If I change the error page declaration to:

<error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/error/errorPage.jspx</location>
</error-page>

The ajax request redirects correctly to my page, but the non-ajax request doesn't redirect anymore to the error page.

So, is this a configuration problem, environment problem or a bug on Omnifaces?

Thanks in advance.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

1

From showcase page:

Please note that the error page must be a valid Facelets page! JSP is not supported.

From javadoc:

This exception handler will parse the web.xml and web-fragment.xml files to find the error page locations of the HTTP error code 500 and all declared specific exception types. Those locations need to point to Facelets files (JSP is not supported).

It's time to convert from JSP to Facelets. JSP is deprecated since 2009 anyway. It works with JSPX extension because it could then be parsed as if it's a Facelets file (which is also XML based).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • OK! I'm using the jspx files but the view handler _is_ facelets. I don't know why the "errorPage.jsf" mapping works correctly with non-ajax requests, but fails with ajax request. – Gustavo Ehrhardt Jan 23 '14 at 00:49
  • The rename of errorPage.jspx to errorPage.xhtml worked. Thank you @BalusC. Just for mention, the CSS on error page must be out of tag for a correct visualization of error page on ajax requests. – Gustavo Ehrhardt Jan 24 '14 at 15:43
  • Yes Gustavo. The head of the error page is not rendered correctly to the browser. The FullAjaxExceptionHandler seems to use/retain the head of the page the error occured on. – Gandalf Jun 10 '14 at 12:14