• Post Reply Bookmark Topic Watch Topic
  • New Topic

Remove managed bean from session  RSS feed

 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSF, when the session times out, as specified in the web.xml - let's say it is set for 2 minutes, what happens to managed beans not explicity removed from the session?

For example:

You use dynamic page navigation. Your user clicks a button with an action method wired in Class1. Class1 has a property for Class2. The action method in Class1 instantiates a Class2 object and calls some of those methods and based on sucess or failure, your page navigates to whatever.

In faces-config.xml you have a managed bean with a scope of session.


Class2 does all of the processing for your JSF application and creates all of the backing beans that act as data placeholders for your JSF page. After the session expires, does Class2 get garbage collected by the container?

If I need to explicitly remove Class2 when the session expires, where does that happen? In a listener in web.xml? When does it happen? I still need the session bean to render the page, so I'm not sure how removing this session bean is going to work, or whether I need to explicitly remove it.

 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When an HttpSession expires or is invalidated, the references to it are removed, making it eligible for garbage collection. If there are no other references to the objects that it refers to, those objects then become eligible for garbage collection as well.

In JSF, Management refers to how the bean is constructed. Once constructed, it's just like any other HttpSession attribute object, and in fact, there's no way to tell the difference.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!