JSF 2:未呈现错误页面的Facelets合成(模板) [英] JSF 2: Facelets composition (template) not rendered for error-page
问题描述
我在Java EE 6应用程序服务器(GlassFish v3)中将JSF 2.0与Facelets结合使用.我在web.xml中为异常配置了一个错误页面:
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>
这是/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,当我单击其中的commandLinks时,有意抛出RuntimeException.发生这种情况时,将显示/error-all.xhtml页面的内容,但不会通过Facelets获取进程,因此 template ="/resources/templates/decorator.xhtml" 没有申请.
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.
使用Google Chrome浏览器,我只能看到标题"和正文",而没有布局.如果我要求Chrome浏览器检查元素,则会获得完整的源代码,其中包括 ui:composition 和 ui:define 标签,而这些标签显然是Chrome无法理解的.这证实了我的理论,即Facelets页面未得到处理.
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.
所以,我的问题是,如何解决这个问题?如何使错误页面得到处理并返回HTML代码,该HTML代码是模板与错误页面的内容相结合的结果?
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?
推荐答案
换句话说,错误页面上的请求是否未通过FacesServlet
传递?您需要相应地更新location
来做到这一点.
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.
例如如果FacesServlet
的url-pattern
是*.jsf
,则需要将location
更新为/error-all.jsf
,而不是普通XHTML" /error-all.xhtml
.
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
.
这篇关于JSF 2:未呈现错误页面的Facelets合成(模板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!