JSF 2:没有为错误页面呈现Facelets组合(模板)

Vít*_*uza 1 java jsf facelets jsf-2

我在Java EE 6应用程序服务器(GlassFish v3)中使用带有Facelets的JSF 2.0.我在web.xml中为异常配置了一个错误页面:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error-all.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

这是/error-all.xhtml测试页面:

<!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>
Run Code Online (Sandbox Code Playgroud)

我实现了一个托管bean,当我点击我的一个commandLinks时,它会故意抛出RuntimeException.当发生这种情况时,会显示/error-all.xhtml页面的内容,但它不会通过Facelets获取进程,因此不会应用template ="/ resources/templates/decorator.xhtml".

使用谷歌浏览器,我只看到"标题"和"正文",结果没有布局.如果我要求Chrome检查这些元素,我会得到完整的源代码,其中包括ui:compositionui:define标记,Chrome显然无法理解.这证实了我的理论,即Facelets页面没有被处理.

所以,我的问题是,如何解决这个问题?如何处理错误页面并返回HTML代码,该代码是模板与错误页面内容组合的结果?

Bal*_*usC 5

换句话说,错误页面上的请求是不是通过了FacesServlet?您需要相应地更新location以使其这样做.

例如,如果url-patternFacesServlet*.jsf,那么你就需要更新location,成为/error-all.jsf替代"普通XHTML" /error-all.xhtml.