detach() method not called, when refreshing browser

I’d like to do some stuff, when my custom component is attached and another job, when it is detached. attach() method is called always and my component is initialized properly, but detach() method is not called when I click refresh button in my browser; it is called only, when the session expires.
Does it exist a way to do some piece of work, when destroying a custom component? Can I capture a proper session event? What is the best way way to achieve it?

This is because unfortunately, it is not possible to reliably send events to the server when a browser window is closing (or in this case, the page is refreshed or navigated away from). However, in the refresh case, it is possible to detect that a new UI is being requested in the same window that already contained a UI, and consequently detach the old UI. This feature has been implemented for Vaadin 7.2, please see
ticket #10338
for details.

Thank you for an answer. Just to clarify: there is no way to do it in Vaadin 7.1? When do you plan to release 7.2 version?

I’m not 100% sure if that works in your case but you should be able to eventially clean up the UI with the
which can call detach when 3 heartbeat calls to the server in a row fail. This will not happen immediately after closing the Tab/Browser/Refreshing and getting a new UI.

Is there any difference between implementing the detach() method in UI (inherited from ClientConnector) and registering a detach listener?

When i tested it in an app with Vaadin 7.1 + Push i couldn’t get the overriden detach method to trigger. Only the DetachListener was fired. Generally i would always recommend you to use the way which gets obviously better supported by the Vaadin Dev Team and this is in my opinion the DetachListener. It feels less like a hack :slight_smile:

Hmm, I wouldn’t expect hacks be described in
Book of Vaadin

Well it isn’t really a hack it just hasn’t such a nice interface as the Listener does :slight_smile:
Also the Book of Vaadin is not yet fully updated to Vaadin 7 so i think in future it will recommend using the Listener instead or at least mention it.

If someone from the Devs sees this. Should someone add a ticket to the
Book of Vaadin 7.1 Roadmap
so that these Listeners get documented besides @Override void attach + detach ?

Btw. I just found another reason for the existence of these listeners

Please create a ticket for the “Documentation” component in Trac, but leave the milestone empty - when he gets to do it will be up to the author of the book.
In general, milestones should only be set by the development team.

I added a ticket

What are the odds of getting a ticketnumber like 12345? :slight_smile:

Thank you all for comprehensive responses. I really appreciate them.

1 in 12345 ? :slight_smile: