会话超时和ViewExpiredException处理对JSF

会话超时和ViewExpiredException处理对JSF

本文介绍了会话超时和ViewExpiredException处理对JSF / PrimeFaces Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这篇文章是有用的非Ajax请求How处理会话过期和ViewExpiredException在JSF 2?但我不能利用这一点时,我使用的是AJAX调用正在提交。

I find this article to be useful for non-ajax request How to handle session expiration and ViewExpiredException in JSF 2?but I can't make use of this when I am submitting using an AJAX call.

假设在一个primefaces对话框,我正在使用AJAX POST请求和会话已经超时。我看到我的网页卡住。

Suppose in a primefaces dialog, I am making a post request using AJAX and session has already timed out.I see my page getting stuck.

如何解决这种场景中,这样当我张贴使用AJAX,我可以重定向他我的观点过期页面,再往前他类似于上面的链接?

How to fix this kind of scenario such that when I post using AJAX, I could redirect him to my view expired page andthen forward him to the login page similar to the solution in the link above?

JSF2 / Primefaces / Glassfish的

JSF2/Primefaces/Glassfish

推荐答案

这在Ajax请求被抛出的异常,在默认情况下在客户端完全没有反馈。只有当你与项目阶段集中运行Mojarra到发展和使用< F:AJAX> ,那么你会得到裸JavaScript警告的异常类型和消息。但除此之外,和在PrimeFaces,默认在那里没有反馈的。但是,您可以看到除了在服务器日志和Ajax响应(web浏览器的开发者工具集的网络部分)。

Exceptions which are thrown during ajax requests have by default totally no feedback in the client side. Only when you run Mojarra with project stage set to Development and use <f:ajax>, then you will get a bare JavaScript alert with the exception type and message. But other than that, and in PrimeFaces, there's by default no feedback at all. You can however see the exception in the server log and in the ajax response (in the webbrowser's developer toolset's "Network" section).

您需要实现一个自定义的<$c$c>ExceptionHandler这确实基本上是以下作业时,有一个 ViewExpiredException 队列中的:

You need to implement a custom ExceptionHandler which does basically the following job when there's a ViewExpiredException in the queue:

String errorPageLocation = "/WEB-INF/errorpages/expired.xhtml";
context.setViewRoot(context.getApplication().getViewHandler().createView(context, errorPageLocation));
context.getPartialViewContext().setRenderAll(true);
context.renderResponse();

另外,你可以使用JSF工具库 OmniFaces 。它有一个<$c$c>FullAjaxExceptionHAndler就是出于这样的目的(来源$ C ​​$ C here,这里展示的演示 )。

Alternatively, you could use the JSF utility library OmniFaces. It has a FullAjaxExceptionHAndler for exactly this purpose (source code here, showcase demo here).

  • Why使用JSF ExceptionHandlerFactory而不是&LT;错误页&GT;重定向?
  • What是对付JSF 2.0例外Aj​​ax化组件的正确方法?
  • Why use a JSF ExceptionHandlerFactory instead of <error-page> redirection?
  • What is the correct way to deal with JSF 2.0 exceptions for AJAXified components?

这篇关于会话超时和ViewExpiredException处理对JSF / PrimeFaces Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:38