JSF 2: Facelets composition (template) not rendered for error-page
Asked Answered
G

2

2

I'm using JSF 2.0 with Facelets in a Java EE 6 application server (GlassFish v3). I have configured an error page for exceptions, in web.xml:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error-all.xhtml</location>
</error-page>

This is the /error-all.xhtml test page:

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                template="/resources/templates/decorator.xhtml">

    <ui:define name="title">Title</ui:define>

    <ui:define name="body">
        <h1>Body</h1>
    </ui:define>
</ui:composition>

I implemented a managed bean that throws a RuntimeException on purpose when I click on one of my commandLinks. When that happens, the contents of the /error-all.xhtml page are shown, but it doesn't get processes by Facelets, so the template="/resources/templates/decorator.xhtml" is not applied.

Using Google Chrome, I see only "Title" and "Body" with no layout as result. If I ask Chrome to inspect the elements, I get the full source code, which includes the ui:composition and ui:define tags, which Chrome obviously doesn't understand. This confirms my theory that the Facelets page is not being processed.

So, my question is, how to fix this? How can I make so the error page gets processed and returns the HTML code that is the result of the combination of the template with the contents of the error page?

Gamecock answered 8/6, 2010 at 15:5 Comment(0)
T
5

In other words, the request on the error page is not been passed through the FacesServlet? You need to update the location accordingly to make it to do so.

E.g. if the url-pattern of the FacesServlet is *.jsf, then you need to update the location to become /error-all.jsf instead of "plain XHTML" /error-all.xhtml.

Tailgate answered 8/6, 2010 at 15:14 Comment(3)
Thanks for your response. I tried that, but it now gives me a HTTP Status 500 error page (standard GlassFish error page) and an exception at the server log: WARNING: org.apache.catalina.core.StandardHostValve@ff2be8: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error-all.faces] javax.servlet.ServletException: No active contexts for scope type javax.enterprise.context.RequestScoped. Also, if I use the NetBeans web.xml editor, I have to choose a file from my project and it uses the exact name of the file. I had to change to .faces manually...Falster
It might be a GlassFish bug: glassfish.dev.java.net/issues/show_bug.cgi?id=11544Falster
Indeed it was. I installed GlassFish 3.0.1 and it worked. Thanks!Falster
A
-2
 <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>


<error-page>
        <error-code>500</error-code>
        <location>/faces/error.xhtml</location>
</error-page>

try doing like that, it worked fine with me. put the url pattern of the faces servlet infront of the location of your error page, instead of error.xhtml it will be /faces/error.xhtml

Alburnum answered 26/6, 2012 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.