使用 t:saveState 相对于会话范围 Bean 的用例和优点?

发布于 2025-01-07 03:57:25 字数 272 浏览 0 评论 0原文

据我所知,t:saveState 允许请求范围 bean 的持续时间比请求范围允许的时间长,但比会话范围 bean 的时间短。您还可以在整个 bean 上使用t:saveState

所以我的问题是,如果您在整个 bean 上使用 t:saveState 与在会话范围中配置 Bean 相比,使用 t:saveState 的优点是什么?

另外,在什么条件下,您会设置 bean 请求范围并使用 T:saveState 而不是设置 bean 会话范围?

谢谢

I understand that t:saveState allows a request scope bean to persist for longer than request scope allows but shorter than session scope bean. You are also able to use t:saveState on an entire bean.

so my question is if you use t:saveState on an entire bean what are the advantage of using t:saveState over having the Bean configured in session Scope?

Also under what conditions do you make the bean request scope and use T:saveState instead of making the bean Session Scope to being with?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江心雾 2025-01-14 03:57:25

引用的 bean 将随着视图的存在而存在。它的功能与新的 JSF 2.0 视图范围基本相同。

当您处理的数据只要您通过在操作方法上返回 nullvoid 与同一视图交互时就应该存在,这特别有用。如果您使用会话范围,则多个视图(同一会话中的多个浏览器窗口/选项卡)将共享相同的数据。当最终用户在多个浏览器选项卡/窗口中与页面交互并在它们之间切换时,这可能会产生不良的副作用。在一个选项卡中完成的所有更改都将反映在另一选项卡中。

会话范围绝对应该仅用于真正的会话范围数据,例如登录用户、其首选项、语言等,这些数据可以在同一会话中的多个浏览器窗口/选项卡之间安全地共享。

另请参阅:

The bean which is referenced by <t:saveState> will live as long as the view lives. It does basically the same as the new JSF 2.0 view scope does.

This is particularly useful when you're dealing with data which should live as long as you're interacting with the same view by returning null or void on action methods. If you would have used the session scope, then multiple views (multiple browser windows/tabs within the same session) would all share the same data. This may have undesireable side effects when the enduser interacts with the page in multiple browser tabs/windows and switches between them. All changes done in one tab would be reflected in the other tab.

The session scope should absolutely only be used for real session scoped data, such as the logged-in user, its preferences, language, etcetera which can safely be shared between multiple browser windows/tabs within the same session.

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文