@ViewScoped bean 在 JSF 中如何以及何时被销毁? [英] How and when is a @ViewScoped bean destroyed in JSF?
问题描述
@RequestScoped
和 @SessionScopedBean
managed beans 的生命周期由 Servlet 容器本身管理,因为它们基本上存储为属性HttpRequest
和 HttpSession
分别是.JSF 如何管理 @ViewScopedBean
的生命周期?我知道它是在创建视图时创建的,并且在回发到不同视图之前一直可用.但我发现在我们从那个视图移开后并没有立即收集垃圾.
The lifecycle of the @RequestScoped
and @SessionScopedBean
managed beans are managed by the Servlet container itself since they are basically stored as an attribute of HttpRequest
and HttpSession
respectively. How do JSF manage the lifecycle of the @ViewScopedBean
? I know it gets created when the view is created and is usable till there is a postback to a different view. But I found out that is not garbage collected immediately after we move from that view.
推荐答案
它会被销毁
执行了非
null
结果的回发,
或者,会话中的(逻辑)视图数量已超过,特定视图是 LRU 链中的第一个视图(在 Mojarra 中,可通过 com.sun.faces.numberOfViewsInSession
和 com.sun.faces.numberOfLogicalViews
上下文参数,每个参数的默认值为 15),
or, the number of (logical) views in session has exceeded and the particular view is the first one in LRU chain (in Mojarra, that's configureable by com.sun.faces.numberOfViewsInSession
and com.sun.faces.numberOfLogicalViews
context parameters, each with a default value of 15),
或者,会话中的活动视图范围的数量已超过(在 Mojarra 中,硬编码限制为 25),另请参见 JSF 2.2 内存消耗:为什么 Mojarra 将最后 25 个视图的 ViewScoped Bean 保留在内存中?
or, the number of actieve view scopes in session has exceeded (in Mojarra, that's a hardcoded limit of 25), see also JSF 2.2 Memory Consumption: Why does Mojarra keep the ViewScoped Beans of the last 25 Views in Memory?
或者,会话已过期.
因此,当由于单击指向另一个页面的 GET 链接、刷新页面或关闭浏览器选项卡/窗口而卸载页面时,它不会被破坏.在满足上述条件之一之前,bean 将一直存在.要在卸载期间销毁它,请考虑使用 OmniFaces @ViewScoped
代替.
It will thus not be destroyed when the page is unloaded as result of clicking a GET link to another page, or refreshing the page, or closing the browser tab/window. The bean will live as long until one of abovelisted conditions is met. To destroy it during unload anyway, consider using OmniFaces @ViewScoped
instead.
这篇关于@ViewScoped bean 在 JSF 中如何以及何时被销毁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!