Greetings,
I’m trying to capture a Window.CloseEvent when a browser window or tab is closed that was opened from the main application using BrowserWindowOpener.
Here’s the code that generates a link that opens a new browser tab/window when clicked:
pocnTable.addGeneratedColumn("button", new CustomTable.ColumnGenerator() {
@Override
public Object generateCell(CustomTable customTable, Object itemId, Object columnId) {
PocnData pd = PocnDao.load(new Integer(itemId.toString()));
Link open = new Link("Open", new ExternalResource(Page.getCurrent().getLocation().toASCIIString() + pd.getPocnNumber()));
open.setWidthUndefined();
BrowserWindowOpener popupOpener = new BrowserWindowOpener(PocnUI.class);
popupOpener.extend(open);
popupOpener.setUriFragment(pd.getPocnNumber());
return open;
}
});
This woks perfectly but I need to catch the event when this new browser window/tab is closed to release access to this record.
Each window is generated from a Servlet. Here is the code that is used when opening the new window/tab, I have added the Window.CloseListener implementation and added the windowClose event handler, but it never fires.
@WebServlet(urlPatterns = "/*", name = "PocnUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = PocnUI.class, productionMode = false)
public static class PocnUIServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener, Window.CloseListener {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void windowClose(Window.CloseEvent e) {
MessageBox
.createInfo()
.withOkButton()
.withCaption("Window Closing");
System.out.println("I wus closed!");
}
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(this);
getService().addSessionDestroyListener(this);
}
@Override
public void sessionInit(SessionInitEvent event)
throws ServiceException {
// Do session start stuff here
}
@Override
public void sessionDestroy(SessionDestroyEvent event) {
// Do session end stuff here
}
}
I don't think this is in the right place but I'm not sure where to implement the Window.CloseListener.
Any help is appreciated and I can include more code if needed.
Thanks,
Mel