繁体   English   中英

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

[英]FullAjaxExceptionhandler only catches javax.el.ELException or java.lang.Throwable

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错误页面包含完全相同的代码,除了标头String标识哪个是哪个。 这是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调用提交表单(我想这是处理程序的目的),并且web.xml上所有3个错误处理程序页面均处于活动状态(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上归零。

FullAjaxExceptionHandler只有解开的根源FacesException 但是,MyFaces ContextAwareELException不是FacesException的子类, FacesException ,它是ELException的子类,因此无法展开。

根据OmniFaces 问题149 ,对FullAjaxExceptionHandler进行了改进,以解ELException 从OmniFaces 1.4开始可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM