2016-09-27 35 views
2

使用AJAX時,有可能知道哪個組件被點擊導致ViewExpiredException被拋出?如果用戶只是試圖註銷並向他顯示正常的註銷頁面,我想避免顯示會話過期頁面。FullAjaxExceptionHandler - 找出哪個組件導致ViewExpiredException?

我想覆蓋shouldHandleExceptionRootCause但我找不到任何東西來確定是否按下注銷按鈕。

我正在使用Mojarra JSF 2.2和Omnifaces 2.5.1。


@Override 
protected boolean shouldHandleExceptionRootCause(FacesContext context, Throwable exception) 
{ 
    UIComponent source = Components.getCurrentActionSource(); 
    if (source != null && "logout".equals(source.getId())) 
    { 
     NavigationHandler nh = context.getApplication().getNavigationHandler(); 
     nh.handleNavigation(context, null, "logout.xhtml?faces-redirect=true"); 
     return false; 
    } 
    else 
    { 
     return super.shouldHandleExceptionRootCause(context, exception); 
    } 
} 

回答

1

Components工具類提供了幾種方法,以識別當前提交的表單,則當前調用的命令和動作事件的源組件(其可以是命令組件本身,而且在ajax事件的情況下也是輸入組件)。

UIForm form = Components.getCurrentForm(); 
UICommand command = Components.getCurrentCommand(); 
UIComponent source = Components.getCurrentActionSource(); 

隨你挑。例如,你可以檢查表格,命令或來源的id,看它是否是所需的。

+0

正是我在找的東西,再次感謝你!在導航到註銷頁面後,是否需要使用類似'OmniPartialViewContext.getCurrentInstance(context).closePartialResponse();'的東西? – lazlev

+0

如果在呈現響應中發生異常,並且已經寫入了部分ajax響應,則只調用'resetPartialResponse()'。通常情況下,ViewExpiredException不是這樣。 – BalusC