本文介绍了在JSF中如何以及何时销毁@ViewScoped bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@RequestScoped@SessionScopedBean 受管bean 的生命周期由Servlet容器本身管理,因为它们基本上分别存储为HttpRequestHttpSession的属性. 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.numberOfViewsInSessioncom.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),

,或者会话中的actieve视图作用域数量已超过(在Mojarra中,这是硬编码限制25),另请参见

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.

这篇关于在JSF中如何以及何时销毁@ViewScoped bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:48