如何清理会话中的特定视图(How to clean up a particular view in the Session)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
如何清理会话中的特定视图(How to clean up a particular view in the Session)

当javax.faces.STATE_SAVING_METHOD设置为server时,每个页面的视图状态将保存在会话映射中。 如果我已经在某个视图中,并且如果我在浏览器中输入URL(GET请求)到同一页面,则将创建一个新视图。 现在我想删除现有视图。 如果我将相关的ViewId包含在get请求路径中或作为GET请求参数,那么使用新的GET请求清理特定的早期视图的最佳方式和地点是什么。 非常感谢您的帮助。

When javax.faces.STATE_SAVING_METHOD is set to server, view state of the each page is saved in session map. If I am already in some view, and if I enter a url in browser (GET request) to the same page, a new view will be created. Now I want to delete the existing view. What is the best way and place, to clean up a particular earlier view with a new GET request, if I have the associated ViewId included in the get request path or as a GET request parameter. Thank you very much for your help.

最满意答案

你不能。 至少不是通过标准API手段。 让它过期。

如果由于目标服务器上的内存占用较少而担心内存使用情况而您打算在无状态模式下使用JSF,并且您正在使用Mojarra 2.1.19或更新版本,请使用

<f:view transient="true">

这样JSF根本不会保存视图状态。 请记住,逻辑结果是您不能再使用视图范围。 视图范围的bean将表现得像请求范围的bean。

另一种方法是降低会话中(逻辑)视图的默认数量。 另请参见com.sun.faces.numberOfViewsInSession vs com.sun.faces.numberOfLogicalViews以了解确切的工作情况。

You can't. At least not by standard API means. Just let it expire.

If you worry about the memory usage because of a low memory footprint on target server and you intend to use JSF in stateless mode, and you're using Mojarra 2.1.19 or newer, just use

<f:view transient="true">

This way JSF won't save the view state at all. Keep in mind that the logical consequence is that you can't use the view scope anymore. The view scoped beans will behave like request scoped beans.

An alternative is to lower the default amount of (logical) views in session. See also com.sun.faces.numberOfViewsInSession vs com.sun.faces.numberOfLogicalViews for the exact working.

更多推荐

本文发布于:2023-04-12 20:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/2f372a7c36fc3d17c6f1a1626cf71ac9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   clean   Session   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!