0

As I wrote in this topic I need to invoke some action when user close or change page. I thought I could use @PreDestroy in my view scoped bean, but it is never called (even when session expires). Is this a bug? I use Glassfish 3.1.2.

Any other suggestions how can I call bean method when user leave page? Is javascript window.onunload good idea?

Community
  • 1
  • 1
karolkpl
  • 2,189
  • 10
  • 39
  • 60

1 Answers1

0

Even if the bean is view scoped, it's the container's responsibility to decide when to collect and destroy unused resources.

The annotations used for defining a scope indicate how long a managed bean has to survive, but you are not guaranteed about when they'll be destroyed.

As you have suggested, JavaScript can be a solution for your problem. See also this answer: How to detect unsaved data in form when user leaves the page?

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117