Is there a way to know if a Vaadin UI has been refreshed (F5 reload) when it is not @PreservedOnRefresh

4.4k views Asked by At

just a question about Vaadin, I searched a lot, without finding a useful information.

I need to know whether a UI has been refreshed when it has NOT @PreserveOnRefresh annotation set (meaning that overriding UI.refresh() will not work for me).

Basically I have a Map which maps a user session id to the opened UIs in the browser, when a new UI is detected I need to add it to the Collection of UIs for the current session.

If the user requests the same UI (same UI implementation mapped by the Servlet @WebServlet configuration) in the browser I need to either add this UI if and only if it is a UI opened in another window of the browser or in another tab, and do nothing or better remove the old UI and put the new UI if the browser window is refreshed.

I know that if I add a @PreservOnRefresh annotation to the UI this will work (but again I need the UI to be not preservable).

So how can I actually do that? I found this implementation (seems a little bit ugly for me) -> http://dev.vaadin.com/ticket/12191#trac-change-5-1374239207261117

Is there another possible way to do that?

Thanks for the attention!

2

There are 2 answers

6
Henri Kerola On

A new UI is created on refresh so could you just add the UI instance to the map in the init method of the UI?

To remove UIs from the map, you can add a DetachListener by calling UI.addDetachListener method. This method will be called when Vaadin detaches the UI from the application.

0
bekce On

Just override refresh() method in your UI class. It works with @PreserveOnRefresh so you don't have to reinitialize your UI instance.

@Override
protected void refresh(VaadinRequest request) {
    super.refresh(request);
    // TODO do your thing here
}