FullAjaxExceptionHandler - 找出哪个组件导致了 ViewExpiredException?
FullAjaxExceptionHandler - Find out which component caused ViewExpiredException?
是否可以判断在使用 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);
}
}
Components
实用程序class提供了几种方法来识别当前提交的表单、当前调用的命令和动作事件的源组件(可以是命令组件本身,也可以是ajax 事件时的输入组件)。
UIForm form = Components.getCurrentForm();
UICommand command = Components.getCurrentCommand();
UIComponent source = Components.getCurrentActionSource();
任你选。例如,您可以检查表单、命令或源的 id
以查看它是否是所需的。
是否可以判断在使用 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);
}
}
Components
实用程序class提供了几种方法来识别当前提交的表单、当前调用的命令和动作事件的源组件(可以是命令组件本身,也可以是ajax 事件时的输入组件)。
UIForm form = Components.getCurrentForm();
UICommand command = Components.getCurrentCommand();
UIComponent source = Components.getCurrentActionSource();
任你选。例如,您可以检查表单、命令或源的 id
以查看它是否是所需的。