簡體   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