我在 Java EE 6 应用程序服务器 (GlassFish v3) 中使用 JSF 2.0 和 Facelets。我在 web.xml 中配置了一个异常错误页面:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error-all.xhtml</location>
</error-page>
这是/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>
我实现了一个托管 bean,当我单击其中一个命令链接时,它会故意抛出 RuntimeException。发生这种情况时,会显示 /error-all.xhtml 页面的内容,但它不会通过 Facelets 获取进程,因此模板=“/资源/模板/decorator.xhtml”不适用。
使用 Google Chrome,我只能看到“标题”和“正文”,没有结果布局。如果我要求 Chrome 检查元素,我会得到完整的源代码,其中包括用户界面:组成 and 用户界面:定义标签,Chrome 显然无法理解。这证实了我的理论:Facelets 页面没有被处理。
所以,我的问题是,如何解决这个问题?我怎样才能处理错误页面并返回 HTML 代码,该代码是模板与错误页面内容组合的结果?
也就是说,错误页面上的请求没有经过FacesServlet
?您需要更新location
相应地使其这样做。
例如。如果url-pattern
of the FacesServlet
is *.jsf
,那么你需要更新location
成为/error-all.jsf
而不是“纯 XHTML”/error-all.xhtml
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)