I have UI components listening on model changes using (for the sake of discussion) something like the BlackBoard add-on.
When a window is closed, I need to unregister the listeners for that window so they don’t leak. Conveniently, this is done in the window close handler.
When a window is refreshed, however, the listeners need to be recreated, but I’m wondering what is the best place to do this. The view’s constructors are not being called, as the view already exists.
What would be the best location to re-create the listeners for the window’s content upon refresh ?
I added a URIHandler to the window in the constructor for my view. When the layout is created the first time, I call the registerHandlers() method for my view. When the window is refreshed, the URI handler is called and , I call registerHandlers() from the URI handler (which just returns null).
Seems to work fine, but using the URI handler is a bit like using a sledge hammer, isn’t it ?
I was wondering about this also. My application instance also serve as listeners for icepush events. I need to register then remove when the browser is closed. Ever come up with a better solution? Also what if the session expires. How would i removed the registed applistener?
What I described works fine (just have to be careful with the URI handler, which is handled separately from the other handlers). It also works fine with windows and subwindows.
The standard servlet API has a way to react to a session close event. You probably want to use some kind of event bus to register the windows instead of registering every single listener (you might want to use a BlackBoard add-on or the industrial-strenght EventBus.org)
One area of improvement for Vaadin 7 could be a rationalization of the event processing – there is a page on the EventBus site about using it in conjunction with Apache Pivot that I find well done (the wiki page in question seems to be down this very minute though)