在后台处理 ViewExpiredException 并恢复表单值

Handle ViewExpiredException in the background and restore form values

是否有无数据库、primefaces 和 "keep-session-alive" 的解决方案来防止或在恢复表单输入时在后台静默处理 ViewExpiredException?

例如,"stay logged-in cookie" 的用户不希望被重定向到某种错误页面或起始页面;他填写了一些表单值,一个小时后回来,然后,当他提交表单时,将使用之前的输入重新创建相同的视图,并再次重新执行底层 requestscope-bean 的提交操作。

我已经注意到 omnifaces 和 mojarras

  <o:enableRestorableView />
  <f:view transient="true"> 

但是当我们谈论永久登录用户时,我不确定这是否是正确的方法。

感谢您指出正确的方向。

the same view is re-created with its previous inputs and the submit-action of the underlying requestscope-bean is re-executed again

对于这个要求,透明地重新创建和恢复过期的 JSF 表单绑定到 request 作用域 bean,无状态 JSF,如 <f:view transient="true"> 中那样是正确的解决方案。

在这种特定情况下,<o:enableRestorableView> 是不必要的。它仅对透明地重新创建和恢复绑定到 view 作用域 bean 的过期 JSF 表单有用。您只需要根据 @PostConstruct.

中的请求参数手动填充视图范围的 bean 属性

换句话说,您不需要混合这些解决方案。它在技术上没有意义,因为视图范围的 bean 在无状态 JSF 中无论如何都是无用的,它们将表现得像请求范围的 beans。

另请参阅:

  • What is the usefulness of statelessness in JSF?
  • Restoring request parameters in @ViewScoped bean after session expires
  • javax.faces.application.ViewExpiredException: View could not be restored