@Destroy Annotation with Page Scoped Beans
I have a page scoped Seam component and it has a no-parameter void method annotated with @Destroy as is shown below. My problem is that destroy method is never called even if the browser page is changed (i.e. page scope ended).
@Name("myPageBean")
@Scope(ScopeType.PAGE)
public class MyPageBean {
@Destroy
public void destroy 开发者_如何学Go{
// Code runs when the component is destroyed.
}
}
Do you have an idea for this issue?
Thanks in advance.
When does the page context get destroyed?
The page scope is indistinguishable from the UI component tree. Therefore, the page context is destroyed when JSF removes the UI component tree (also called the view) from the session. However, when this happens, Seam does not receive a callback and therefore the @Destroy method on a page-scoped component never gets called. If the user clicks away from the page or closes the browser, the page context has to wait to get cleaned up into JSF kills the view to which it is bound. This typically happens when the session ends or if the number of views in the session exceeds the limit. This limit is established using the com.sun.faces.numberOfViewsInSession and com.sun.faces.numberOfLogicalViews context parameters in the Sun implementation. Both default to 15. However, it's generally best not to mess with these values.
The page scope should be seen merely as a way to keep data associated with a view as a means of maintaining the integrity of the UI component. This focus is especially relevant for data tables, which have historically been problematic. I would not use the page scope as a general storage mechanism for use case or workflow data. A good way to think of it is as a cache.
http://www.seamframework.org/42514.lace
do you ever use this bean in a page?, if not, I guess the destroy will not be called because of it never be created. or you can add @StartUp to force creating the bean when the Scope are initialized.
精彩评论