jsf - ViewExpiredException 错误页面未显示

标签 jsf jsf-2.2 glassfish-4 viewexpiredexception

我让一些带有表单的选项卡打开,当我按下命令按钮时( session 过期一段时间后)我收到一个 java 脚本警报说:

serverError: class javax.faces.application.ViewExpiredException viewId:/register.xhtml - View /register.xhtml could not be restored.



在 firefox 上(本地的 glassfish 4)

我已经添加了 :
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/index.xhtml?faces-redirect=true</location>
</error-page>

在我的 web.xml但我没有被重定向到我的索引。这是为什么 ?

编辑:示例按钮
<h:commandButton value="Register" action="#{userController.register}">
    <f:ajax execute="@form" render="@form" />
</h:commandButton>

UserController 是 ViewScoped

最佳答案

如果您查看 JSF-2.2 spec 的第 13.3.6.3 和 13.3.6.4 节,这是预期的行为。 ,至少如果你有

<context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>
  <param-value>Development</param-value>
</context-param>

在您的 web.xml (它会默默地忽略生产模式下的错误)。当您单击该按钮并接收到时,JSF 客户端代码会发送一个 AJAX 请求
<error>
    <error-name>...</error-name>
    <error-message>...</error-message>
</error>

与您的 ViewExpiredException在回应中。然后预期客户端代码对该错误信息使用react。使用 onerror 注册一个函数(在 f:ajax 标签上)或 addOnError (在 jsf.ajax 对象上)自己处理错误。

由于很多人希望服务器在此类问题上指导客户端,因此omnifaces 包括 FullAjaxExceptionHandler这基本上会重置您的响应并发送您指定的错误页面。

另见:

Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

关于jsf - ViewExpiredException 错误页面未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800128/

相关文章:

JSF 复合组件接口(interface)标记 "expert"属性。它是做什么用的?

ajax - 重新加载 <p :dataScroller> on a form update

java - 无法从 Swing 客户端创建初始上下文

mysql - glassfish 4 & MySQL & JSTL

jsf - 使用动态列过滤惰性数据表

JSF。转换 h :commandLink display 的值

ajax - PrimeFaces 对话框仅在第一次出现时进行验证

eclipse - 使用 glassfish 4.1 为阔叶商务设置 netbeans 需要什么?

jsf - Primefaces 数据表 : need to export additional columns to excel that are not displayed on datatable

jsf - 生成要在 Facelets 中显示的链接列表