FullAjacExceptionHandler只能捕获javax.el.ELException或java.lang.Throwable。 Throwable也优先于javax.el.ELException。我需要显式捕获托管bean引发的特定异常。然而,ELException显然包装了根本原因异常(即LoginFailedException)。我使用JSF 2(MyFaces 2.1.10),Spring EL解析器(Spring managed beans),el-api-2.2和glassfish el-impl-2.2。FullAjaxExceptionhandler只捕获javax.el.ELException或java.lang.Throwable
这里的错误:
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处理。
希望能够澄清我的情况。
UPDATE:
现在我使用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中归零。
请张贴你的功能需求,你有什么试图解决它,否则没有人可以帮助你。 – 2013-03-04 01:35:35
谢谢@Luiggi。我编辑了我的帖子以供澄清。希望能帮助到你。目前,这只是一个实验/演示。我唯一的要求是使用FullAjaxExceptionHandler和适当的错误页面显示托管bean抛出的自定义异常。 – 2013-03-04 02:11:55
来自OmniFaces的代码片断表明它解开了异常以得到根本原因并标识了错误页面。我猜BalusC可以最好地回答这个问题:-) – 2013-03-04 02:22:19