Opening a UI in a popup window

To open a new popup window in the browser showing another part of your application, you can use the new BrowserWindowOpener extension. Any component or MenuItem that you extend with BrowserWindowOpener will make clicking the component open a new browser window with some options for the content. Opening a popup this way helps you bypass most popup blockers.

One of the things that BrowserWindowOpener can be configured to open in the new window is a new instance of a Vaadin UI class.

Java

  1. public class OpeningUIInPopup extends UI {
  2. @Override
  3. protected void init(VaadinRequest request) {
  4. Button popupButton = new Button("Open popup with MyPopupUI");
  5. BrowserWindowOpener popupOpener = new BrowserWindowOpener(MyPopupUI.class);
  6. popupOpener.setFeatures("height=300,width=300");
  7. popupOpener.extend(popupButton);
  8. // Add a parameter
  9. popupOpener.setParameter("foo", "bar");
  10. // Set a fragment
  11. popupOpener.setUriFragment("myfragment");
  12. setContent(popupButton);
  13. }
  14. }
  15. public class MyPopupUI extends UI {
  16. @Override
  17. protected void init(VaadinRequest request) {
  18. setContent(new Label("This is MyPopupUI where parameter foo="
  19. + request.getParameter("foo") + " and fragment is set to "
  20. + getPage().getUriFragment()));
  21. }
  22. }

In this example, a Button is created and extended with a BrowserWindowOpener. Furthermore, the size of the popup window is defined. See https://developer.mozilla.org/en-US/docs/DOM/window.open#Position_and_size_features for a description of the commonly supported features. If you don’t define any features, the browser will use its default setting which usually makes it open a new tab instead of opening a popup window.

The BrowserWindowOpener can also be used to open a Resource or any URL that you define using different constructors.