JSF2 ExceptionHandler不处理correclty bean实例化异常

时间:2012-01-27 14:47:13

标签: exception-handling jsf-2 managed-bean

我正在使用JSF 2.0 ExcepctionHandler机制来处理我的应用程序中的所有异常。

public void handle() throws FacesException
{
  FacesContext fc = FacesContext.getCurrentInstance();

  for (Iterator<ExceptionQueuedEvent> i =
      getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();)
  {
    ExceptionQueuedEvent event = i.next();
    ExceptionQueuedEventContext context =
        (ExceptionQueuedEventContext)event.getSource();

    // ... other treatments ...

    final Application application = fc.getApplication();
    final NavigationHandler navigationHandler =
        application.getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "error");
    fc.renderResponse();
    i.remove();
  }
}

handleNavigation适用于几乎所有抛出的异常,但JSF bean实例中的错误除外。所有错误通常都会重定向到页面error.xhtml。

但是,在index.xhtml中我得到了这个:

<h:ouputText value="#{user.name}"/>

如果user构造函数抛出异常,我收到此错误:

javax.el.ELException: /index.xhtml: Cant instantiate class: com.test.user.bean.User.
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
    at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276)
    at org.richfaces.renderkit.html.PopupPanelRenderer.encodeEnd(PopupPanelRenderer.java:534)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
    at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276)
    at org.richfaces.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:57)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:509)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:20654)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.test.user.bean.User.
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:224)
    at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:148)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
    ... 61 more

在这种情况下,ExceptionHandler调用handleNavigation但没有任何反应,在浏览器中,这会导致空白页!

为什么这个异常不会像其他异常一样处理?

JSF 2.0.6(mojarra) RichFaces 4.1决赛 Tomcat 6.0.18 JDK 1.6.0_20

0 个答案:

没有答案