Kerb
Kerb

Reputation: 1168

Vaadin multiple browser windows/tabs

I'm developing an application using Vaadin framework. The application has a main menu, when user clicks a menu item, application executes descendant of AbstractMenuCommand class like

public class RunReportCommand extends AbstractMenuAction {
@Override
public void execute() throws MenuException {
    Window = .... // create window here
    openWindow(window);
}
protected void openWindow(Window window) {
    application.getMainWindow().open(new ExternalResource(window.getURL()));
    application.setMainWindow(window);
}

}

After this main browser window content is replace with needed window. After spending a lot of time I came to this solution: if you want replace browser window content with Vaadin Window you should always do

    application.getMainWindow().open(new ExternalResource(window.getURL()));
    application.setMainWindow(window);

Recently I got a new task to add a feature to application: users should have ability open windows in diffirent tabs and so the problem is that I have only one main window in vaadin (and window.open works only for the main window) but user can have a lot of diffirent windows in diffirent browser tabs, so if user clicks a menu item in browser tab that contains not main window, reloading vaading window content won't work.

Upvotes: 2

Views: 5184

Answers (2)

Basil Bourque
Basil Bourque

Reputation: 340350

Vaadin 7 & Vaadin 8

With versions 7 and 8 came the new concept and class of UI. You can now very easily open another window/tab in the user’s web browser. Fantastic new feature and great advantage for the Vaadin platform to support multi-window apps.

All the open windows/tabs share the same user session.

The tricky part is that for purposes of security and avoiding obnoxious behaviors, browsers do not allow JavaScript to directly open another window, known as "pop-up window". The new window/tab can only be opened as a direct result of a user gesture such as clicking a button.

So in Vaadin, you must use associate a BrowserWindowOpener object with a Button. You pass the .class of your UI subclass you wrote. That UI subclass is automatically instantiated for you, and displayed in the new window/tab.

All of this is explained well in the Handling Browser Windows page in the manual.

One limitation is that I see no direct way to pass objects to the new window/tab, that new UI-subclass instance. You might be able to do so indirectly. Perhaps posting an attribute in the session. Or perhaps setting string parameters on the URI of the new window/tab. I have asked about this issue of passing information to the new window for Vaadin 7 and asked again for Vaadin 8.

Vaadin 6

In 2011, I spoke with members of the Vaadin development team about the issue of multiple web browser windows or tabs for the same Vaadin 6 app. They strongly recommended against doing so. They said while it is possible, doing so requires much effort and tends to be troublesome and error-prone.

Instead they suggested using Vaadin TabSheet within a single browser window/tab.

The TabSheet is quite dynamic, so you can add and drop tabs as needed. Performance is surprisingly fast in my experience. Remember that only the content of the frontmost tab is actually in the user's browser window. The other tabs' content is in memory on the server, but is not a burden to the web browser/client. While tabs cannot be word wrapped and so tend to be wide, the TabSheet automatically provides scrolling through too many tabs to show.

Upvotes: 3

user973999
user973999

Reputation:

Until release of Vaadin7, you can look at Navigator7 add-on (found here)

Navigator7 allows multi browser tabs navigaton. (A click in a browser tab, only affect this browser tab)

We use it in our application and it's work verry well.

Regards.

Upvotes: 1

Related Questions