views:

1141

answers:

2

Hey all,

In a JSF application, I want to remove a session-scoped managed bean when the user closes their browser window. I've used a link before that executes the following:

session.removeAttribute("<nameOfManagedBean>");

This seems to do the trick nicely. However, I'd like this same code to run even if a user clicks on the "X" on their browser.

Is their some way of detecting this event properly on any browser?

+2  A: 

In any browser? No. Even getting this to work in some browsers (major browsers, assuming javascript is on, etc...) is no piece of cake because it's not that easy to distinguish between user closing the window altogether, navigating to another site or even another page of your application.

Perhaps you can use session timeout instead? Either by setting it directly via setMaxInactiveInterval() method or - if you only want to remove this single bean while leaving the session itself intact - by periodically checking getLastAccessedTime() via background thread and removing the bean once timeout reaches whatever value you deem necessary.

ChssPly76
A: 

As an aside, I have solved this problem specifically for Internet Explorer 6.0 (the browser I am supporting for my client...yes, my head hurts too after reading that sentence...) utilizing the ICEFaces JSF Framework. I have written up a description here.

KG