- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
简化后,我的错误处理程序如下所示:
@Override
public void handle() throws FacesException {
Iterator<ExceptionQueuedEvent> unhandledExceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator();
FacesContext context = FacesContext.getCurrentInstance();
if (unhandledExceptionQueuedEvents.hasNext()) {
Throwable exception = unhandledExceptionQueuedEvents.next().getContext().getException();
unhandledExceptionQueuedEvents.remove();
context.getExternalContext().dispatch("/error.jsf");
}
while (unhandledExceptionQueuedEvents.hasNext()) {
unhandledExceptionQueuedEvents.next();
unhandledExceptionQueuedEvents.remove();
}
}
简化的 template.xhtml
<html>
<f:view>
<h:head>
<!-- some stuff here -->
</h:head>
<h:body>
<div id="menu"><!-- menu content --></div>
<div id="content">
<ui:insert name="body"></ui:insert>
</div>
</h:body>
</f:view>
</html>
错误.xhtml
<html>
<ui:composition template="/template.xhtml">
<ui:define name="body">
ERROR
</ui:define>
</ui:composition>
</html>
但是在渲染 error.jsf 时,使用 ui:composition 进行模板化会出错。 JSF 一直渲染 template.xhtml 直到 ,然后重新开始渲染模板。结果是一个菜单呈现两次的页面,所有资源再次包含在页面中间。它的开头看起来像这样:
<div id="menu></div>
<div<?xml version="1.0" encoding="UTF-8" ?="">
<!-- Page included once more -->
这之后是服务器上的无限循环,导致数百万条日志行一遍又一遍地包含以下位
at com.xdin.competence.web.error.ErrorHandler.handleException(ErrorHandler.java:123) [:]
at com.xdin.competence.web.error.ErrorHandler.handle(ErrorHandler.java:108) [:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:115) [:2.0.3-]
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107) [:2.0.3-]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:541) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.0.0.Final]
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:542) [:2.0.3-]
at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:89) [:2.0.3-]
at org.jboss.seam.faces.environment.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$C:$JBoss$jboss-6$0$0$Final$server$career$deploy$career-portal$war"-ManagedBean-class_org$jboss$seam$faces$environment$SeamExternalContext_$$_WeldClientProxy.dispatch(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$C:$JBoss$jboss-6$0$0$Final$server$career$deploy$career-portal$war"-ManagedBean-class_org$jboss$seam$faces$environment$SeamExternalContext_$$_WeldClientProxy.java) [:3.0.1.Final]
知道原因是什么吗?
最佳答案
您不应使用 ExternalContext#dispatch()
来呈现 JSF View 。它应该只用于转发到非 JSF 资源。您应该改为通过 FacesContext#setViewRoot()
设置所需的 JSF View 并让 JSF 渲染它。
ViewHandler viewHandler = context.getApplication().getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(context, viewId);
context.setViewRoot(viewRoot);
context.renderResponse();
或者,如果您当前已经处于渲染响应中,那么让 JSF 重新渲染它就太晚了。您需要手动构建和呈现新 View 。在这种情况下,将最后一行替换为:
ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(context, viewId);
vdl.buildView(context, viewRoot);
context.getApplication().publishEvent(context, PreRenderViewEvent.class, viewRoot);
vdl.renderView(context, viewRoot);
context.responseComplete();
请注意,如果响应已经提交,则为时已晚。您可能还想事先检查一下。
您可能会找到 source code的 OmniFaces FullAjaxExceptionHandler
有助于获得一些见解。
关于jsf-2 - 在 JSF 错误处理程序中使用 ExternalContext.dispatch 会导致页面呈现损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15474345/
这是我的 demo.xhtml 页面: Hello Demo Portlet!!!! Client 当我在不使用标签的情况下将它部署到门户页面时,它工作正常。
我有两页: String page1 = "user/newuser.jsf"; String page2 = "department/newdepartment.jsf"; 如果我重定向到 page
在 p:ajax 调用上,监听器调用包含 FacesContext.getCurrentInstance().getExternalContext().dispatch("/uri.jsf"
我正在使用 ExternalContext.redirect(String); 将用户重定向到另一个页面的方法: FacesContext.getCurrentInstance().addMessag
我正在尝试在我的托管 bean 中获取一个 PNG 文件作为 InputStream,如下所示: ExternalContext externalContext = FacesContext.getC
当我尝试通过 http://localhost/home/index.html 访问我的开发站点时出现此错误重定向到 http://localhost/home/views/main/index.xh
我正在尝试使用 Exadel Fiji 来渲染饼图。 谁能告诉我 el #{facesContext.externalContext.requestContextPath} 是什么意思? 最佳答案 它
我的 JSF Web 应用程序显示以下错误: /index.xhtml Not Found in ExternalContext as a Resource. 我的目录结构是: - Java 资源 -
在 OmniFaces 中,FullAjaxExceptionHandler找到要使用的正确错误页面后,调用 JSF 运行时来构建 View 并呈现它,而不是包含 AJAX 调用的页面。 为什么这个?
FacesContext 和有什么区别和 ExternalContext ?我什么时候可以使用其中一种?一个有什么,另一个有什么? 以下示例来自 JavaServer Faces 第 3 版一书:
尝试在我们使用的 jsf 应用程序中使用 jsp、servlet 和 java 更改一个 jsf 应用程序 ExternalContext exctx = FacesContext.getCurren
我现有的应用程序是用某种手工制作的 JSP 编写的。它包含一个派生自 HttpServlet 的类,用于处理所有请求和它自己的 HTML 模板语言。我正在尝试使用通用的 JSF 模板语法重写它。现在我
这是一个可以抛出异常的示例按钮: 在我的 ExceptionHandler我有: FacesContext.getCurrentInstance().getExternalContext
考虑一个页面webapp/myPage.xhtml: ... ... ... ... ... 按钮 Action 绑定(bin
我正在尝试从 ExternalContext 检索 Web 应用程序的根 URL , 但无法理解使用哪种方法... 最佳答案 更简洁的方式是: HttpServletRequest request =
简化后,我的错误处理程序如下所示: @Override public void handle() throws FacesException { Iterator unhandledExcep
在 JSF1 中,您可以访问当前 FacesContext 的 bean 实例。经过 ExternalContext ec = FacesContext.getCurrentInstance().ge
我在启动应用程序时遇到此错误。 com.sun.faces.context.FacesFileNotFoundException: /faces/index.xhtml Not Found in Ex
我在 WebSphere 上使用 JSF 1.1 (MyFaces 1.1.8) 时遇到问题。在 Tomcat 5.5 上部署我的应用程序时,此行为不适用,一切正常。 当我尝试从 Ogone(支付网关
我正在尝试开发一个控制台制作的 JSF2 end Primefaces,它在 spring boot 中的嵌入式 tomcat 上运行。这是我的项目配置: pom.xml org.sprin
我是一名优秀的程序员,十分优秀!