Browser close event in Vaadin 7

In browser (Window/Tab) close I have to call logout functionality.

Does Vaadin 7 have browser close event ?

If there is no API for this, is javascript the only solution for this problem ?

What about using search functionality?
Hint:
https://vaadin.com/search?q=browser+close+event+&refinement=forum

There is no predefined API for getting
Browser Close Event
.
I need to sense
Browser Close Event
and call
Session Close
.
Can someone help me out with this ?

From the search results of link above, you can see, that there is no way to reliably detect browser close event. Try to read listed posts, how to resolve the issue best (e.g setting proper hearbeat interval).

Setting heartbeat won’t solve my porblem. Session heartbeat senses inactive session time thats not what I am looking for.

The Browser Close Listener in Vaadin 7 is UI.addDetachListener(…);

Also Heartbeat is not there to sense inactive Sessions but instead tries to detect inactive UI’s and detaches them if it finds one.

For more information have a look at Chapter 4.7.5
https://vaadin.com/book/vaadin7/-/page/application.lifecycle.html

I just wanted to add to Marius’s explaination that I found works through trial and error. Maybe someone else is looking to acheive the same close mechanism this may reduce the need for a lot of configuration evaluation.

I have a project (7.2.1) that needs to remain functional as long as the web page is not closed. The server pushes data to the user every couple of seconds. This mechanism works well, but I had a hard time trying to maintain the function that I wanted to acheive for my users. I could not use the closeIdleSession because the user will not be interacting with the web page much, purely just monitoring the UI changes. The closeIdleSession does not take the heartbeat into consideration for its idle evaluation.

I tried several combinations in my web.xml before finding the proper configuration that I needed. With the combination below, I now have the control that I wanted that allowed the page not to timeout but still detect the closure of the web page from the client so that I could release my resources.

<context-param> <param-name>heartbeatInterval</param-name> <param-value>30</param-value> </context-param> <session-config> <session-timeout>5</session-timeout> </session-config> <init-param> <param-name>closeIdleSessions</param-name> <param-value>false</param-value> </init-param> With this configuration, the heartbeat close detection works great and the web page does not get a timeout to close the UI while the user is monitoring the changes. Which is what I was trying to achieve.

In the main UI class I just used:

[code]
this.addDetachListener(new DetachListener()
{
private static final long serialVersionUID = 1L;

@Override
public void detach(DetachEvent event)
{
    // Realease any resources
}

});
[/code]and that gave me access to my resources to be released on a UI basis.

This was just to provide some assistance for anyone else looking to acheive a reliable close detection with no premature UI closure.

Regards,
Eric