Open Window with on demand URL (BrowserWindowOpener)

This is related to the question with an on demand file download.

How does one determine the URL of the window to open only when the user has clicked a component that has a BrowserWindowOpener attached?

I tried overriding handleConnectorRequest() but I could not get it to work this way.

This would be difficult to do due to how BrowserWindowOpener must work in order to play nicely with popup blockers. The click handler and window opening logic resides on the client side, so the server doesn’t get an opportunity to change anything between the click and the window opening. If there were a server roundtrip inbetween, many popup blockers would be triggered due to the popup not being a direct result of a user action.

A workaround might be to open a special UI that knows (eg. based on info in the session) where to redirect (eg. using Page.setLocation() or Navigator).

In Vaadin 7.1, one could probably use server push to keep BrowserWindowOpener’s clientside state up to date so that it always knows what page to open.

Ok, the method with the separate UI seems to work. Alas, init() is only called once (per session).
Which method is called every time, the tab with the UI is opened or the URL is changed?

I would like to reuse the window to display different content from different URLs.

Hmm, in that case you could probably use BrowserWindowOpener just once, to open a window with some known window name, and after that use a regular server-side click listener that calls Page.open() with the window name. I don’t think popup blockers interfere with changing the location of a window that’s already open, even if it’s done by the server.

In order to be able to reuse the BrowserWindoeOpener, I now close the UI after it has successfully redirected the user to where he needs to go.