FullAjaxExceptionhandler只捕获javax.el.E​​LException或java.lang.Throwable

时间:2013-03-04 01:08:16

标签: java jsf jsf-2 spring-el omnifaces

FullAjacExceptionHandler只能捕获javax.el.E​​LException或java.lang.Throwable。 Throwable也优先于javax.el.E​​LException。我需要显式捕获托管bean抛出的特定异常。但是,ELException显然包含了根本原因异常(即LoginFailedException)。

我正在使用JSF 2(MyFaces 2.1.10),Spring EL解析器(Spring托管bean),el-api-2.2和glassfish el-impl-2.2。

这是错误:

Ajax request: No
Status code: 500
Exception type: class org.apache.myfaces.view.facelets.el.ContextAwareELException
Exception message: javax.el.ELException: org.tests.omnifaces.exception.LoginFailedException: Login failed.
Stack trace: org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: org.tests.omnifaces.exception.LoginFailedException: Login failed.
...

LoginFailedException是一个简单的自定义异常。 我将不胜感激任何帮助。提前谢谢。

编辑: 实验完成:

我创建了3个错误页面,以查看在抛出LoginFailedException时将调用/使用哪个页面。 XHTML错误页面包含完全相同的代码,但标题字符串除外,它标识哪个是哪个。这是web.xml错误条目:

<error-page>
    <exception-type>org.tests.omnifaces.exception.LoginFailedException</exception-type>
    <location>/pages/errors/loginError.xhtml</location>
</error-page>

<error-page>
    <exception-type>javax.el.ELException</exception-type>
    <location>/pages/errors/elException.xhtml</location>
</error-page>

<error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/pages/errors/catchAllThrowable.xhtml</location>
</error-page>

将使用catchAllThrowable.xhtml。如果我删除(在web.xml上注释掉)Throwable,将使用ELException.xhtml。如果我删除ELException,异常将由容器(tomcat)处理,而不是由loginError.xhtml处理。

希望这能澄清我的情况。

更新:

我现在正在使用AJAX调用提交表单(我想这是处理程序的目的),所有3个错误处理程序页面在web.xml上都是活动的(Throwable,ELException,LoginFailedException):

<h:commandButton id="loginButton" value="Login" action="#{login.loginUser}">
    <f:ajax execute="@form" render="@form messages" />
</h:commandButton>

已跳过Throwable,并且匹配了ELException(渲染了elException.xhtml)。仍然无法在LoginFailedException上归零。

1 个答案:

答案 0 :(得分:0)

FullAjaxExceptionHandler仅解开FacesException的根本原因。但是,MyFaces ContextAwareELException不是FacesException的子类,而是ELException的子类,因此仍然是未解包的。

根据OmniFaces issue 149FullAjaxExceptionHandler已得到改进,以解开ELException。这可以从OmniFaces 1.4开始提供。