@PreserveOnRefresh - 目的和需要? [英] @PreserveOnRefresh - Purpose and need?

查看:36
本文介绍了@PreserveOnRefresh - 目的和需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对@PreserveOnRefresh 注释的目的有疑问.这个特定注释的目的是什么,它必须在哪些场景中使用?使用/不使用这个注解有什么影响?

I have a doubt regarding the purpose of @PreserveOnRefresh annotation. What is the purpose of this particular annotation and what are the scenarios in which it has to be used? What are the effects of using/not using this annotation?

谢谢,丹尼肯副总裁

推荐答案

other answer 如上所述并不完全正确在评论中(总结在这里).

The other answer is not quite correct as noted in the comments (summarized here).

此答案适用于 Vaadin 7.

This Answer applies to Vaadin 7.

Vaadin 6 在某些方面有所不同.

Vaadin 6 is different in some ways.

只要用户的浏览器到达您的 Vaadin 应用,就会创建一个 Servlet 会话.VaadinSession 包含 一个包装器 围绕该 Servlet 会话,可通过 VaadinSession.getSession().

As soon as a user’s browser reaches your Vaadin app, a Servlet session is created. The VaadinSession contains a wrapper around that Servlet session, reachable via VaadinSession.getSession().

会话一直持续到发生超时、您明确关闭它、用户退出浏览器应用程序或其他此类终止事件.但是用户点击重新加载/刷新功能不是这样的终止事件.

The session continues until a time-out occurs, you explicitly close it, user quits the browser app, or other such terminating event. But the user hitting the Reload/Refresh feature is not such a terminating event.

在该会话进行期间,用户可以单击/轻触 Web 浏览器中的重新加载/刷新"图标功能.默认情况下,这会导致您当前的 UI 子类对象被新的新 UI 子类对象替换.

While that session is on-going, the user may click/tap the Reload/Refresh icon feature in the web browser. By default this causes your current UI subclass object to be replaced by a new fresh UI subclass object.

对于您的用户,您的应用似乎已重新启动.但实际上您的应用没有被中断,只有那个特定浏览器窗口/选项卡中的内容被丢弃了.您的应用程序(您的 VaadinSession)继续存在.

To your user, it appears your app has restarted. But actually your app was not interrupted, only the content in that particular browser window/tab was discarded. Your app (your VaadinSession) lives on.

您的应用可能打开了其他浏览器窗口/选项卡,每个窗口/选项卡都有自己的 UI 子类对象.那些其他窗口/选项卡仍将使用相同的 UI 对象运行.所有正在运行的 UI 实例都绑定到相同的 VaadinSession.

Your app may have had other browser windows/tabs open, each with their own UI subclass object. Those other windows/tabs would still be running with the same UI object. All of those running UI instances are tied to the same VaadinSession.

您可能希望也可能不希望在浏览器窗口/选项卡的重新加载/刷新时丢弃您的 UI 子类对象,具体取决于您的特定应用程序的性质.

You may or may not want your UI subclass object discarded on a Reload/Refresh of the browser window/tab, depending on the nature of your particular app.

您是否希望用户能够重头再来",从头开始?如果是这样,请保留此默认行为.不应用注释.

Do you want the user to be able to do a "do over", to start again from scratch? If so, keep this default behavior. Do not apply the annotation.

如果要更改浏览器重新加载/刷新的效果以保持 UI 对象及其状态,请应用 PreserveOnRefresh 注释.很简单,就像魔术一样.

If you want to change the effect of a browser Reload/Refresh to keep the UI object and its state, apply the PreserveOnRefresh annotation. Easy, almost like magic.

在 Vaadin 7 中,您可以在浏览器窗口/选项卡级别(a UI 实例)或应用程序范围(在 VaadinSession 上).

In Vaadin 7, you may store state either at the level of a browser window/tab (a UI instance) or app-wide (on VaadinSession).

如果您希望某些数据在 UI 对象,通过调用 get/setAttribute 方法将该数据存储在 VaadinSession 上.例如,您将在 VaadinSession 上保留用户登录/身份验证信息.

If you want some data to survive the discarding of a UI object, store that data on the VaadinSession by calling the get/setAttribute methods. For example, you would keep user login/authentication information on the VaadinSession.

要了解更多这两个级别的范围,包括有关线程安全的关键信息,请参阅另一个问题,如何将数据放入会话变量并在 vaadin 中获取不同页面中的数据?.

To learn more these two levels of scope, including crucial information about thread-safety, see this other question, how to put data in session variable and get the data in different page in vaadin?.

此图显示了会话层次结构.上面三层(Servlet Container、ServletContext、HttpSession)都是标准的Servlet技术.下面是 Vaadin 特定的级别.

This diagram shows the session hierarchy. The upper three levels (Servlet Container, ServletContext, and HttpSession) are all standard Servlet technology. Below those are the Vaadin-specific levels.

这篇关于@PreserveOnRefresh - 目的和需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆