FullAjaxExceptionHandler - 找出导致ViewExpiredException的组件?

时间:2016-09-27 09:03:52

标签: jsf omnifaces

使用AJAX时,是否可以判断哪个组件被点击导致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 个答案:

答案 0 :(得分:1)

Components实用程序类提供了几种方法来标识当前提交的表单,当前调用的命令和操作事件的源组件(可以是命令组件本身,但也可以是输入组件) ajax事件)。

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

接受你的选择。例如,您可以检查表单,命令或来源的id,看看它是否是所需的。

相关问题