webtier@glassfish.java.net

Re: _at_PreDestroy on a ViewScoped managed bean

From: <webtier_at_javadesktop.org>
Date: Thu, 08 Oct 2009 21:27:28 PDT

That's fair, and I realize it's not such a simple thing. I hope the book authors are paying attention, because if you read what's out there today you can get a different impression.

To follow up on the other PreDestroy issue, here are some observations. I realize starting and stopping the server is kind of artificial, but I don't know how else to make it serialize the session.

1. PreDestroy on a SessionScoped bean always seems to get called twice.

2. If you shut down the web server, it serializes the SessionScoped bean and then calls its PreDestroy. When you restart the server, it deserializes the bean and you can continue with the page, but the bean has already had PreDestroy called. Then when you start a new session, PreDestroy is not called on the bean. (as it would be for an instantiated bean.)

3. If you shut down the web server, it serializes the ViewScoped bean in the current view. When you restart the server, it deserializes the bean and you can continue with the page, but when you go to a new page (with h:commandLink) PreDestroy is never called on the bean (as it would be for an instantiated bean.)

4. You can no longer use a SessionScoped bean as an HttpSessionBindingListener to find out when the session ends because it gets added to and removed from the session many times (but of course you can use an anonymous or other class that is not a managed bean).

Again, these are not issues for me, I just wrote them up here in case they are bugs, or anyone else needs to know.
[Message sent by forum member 'judys' (judy_at_apprisant.com)]

http://forums.java.net/jive/thread.jspa?messageID=367370