Handle ViewExpiredException in the background and restore form values

廉价感情. 提交于 2019-12-19 04:32:08

问题


Is there a database-, primefaces- and "keep-session-alive"-free solution to prevent or to handle a ViewExpiredException silently in the background while restoring the form-inputs?

for example a user with a "stay logged-in cookie" would prefer not to be redirected to some kind of an error- or start-page; he fills out some form values, comes back in an hour and then, when he submits the form, the same view is re-created with its previous inputs and the submit-action of the underlying requestscope-bean is re-executed again.

i already took notice of omnifaces and mojarras

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

but as we talk about permanent logged-in users, i am not shure, if this would be the right approach.

thanks for pointing into the right direction.


回答1:


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

For exactly this requirement, transparently recreating and restoring an expired JSF form tied to a request scoped bean, stateless JSF as in <f:view transient="true"> is the correct solution.

The <o:enableRestorableView> is unnecessary in this specific case. It is only useful for transparently recreating and restoring an expired JSF form tied to a view scoped bean. You only still have to manually populate the view scoped bean properties based on request parameters in its @PostConstruct.

In other words, you don't need to mix those solutions. It does technically not make sense as view scoped beans are useless anyway in stateless JSF, they will behave like request scoped beans.

See also:

  • 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


来源:https://stackoverflow.com/questions/40745048/handle-viewexpiredexception-in-the-background-and-restore-form-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!