You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpeningAUIInAPopupWindow.asciidoc 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ---
  2. title: Opening A UI In A Popup Window
  3. order: 79
  4. layout: page
  5. ---
  6. [[opening-a-ui-in-a-popup-window]]
  7. = Opening a UI in a popup window
  8. To open a new popup window in the browser showing another part of your
  9. application, you can use the new `BrowserWindowOpener` extension. Any
  10. component or `MenuItem` that you extend with `BrowserWindowOpener` will make clicking
  11. the component open a new browser window with some options for the
  12. content. Opening a popup this way helps you bypass most popup blockers.
  13. One of the things that `BrowserWindowOpener` can be configured to open
  14. in the new window is a new instance of a Vaadin UI class.
  15. [source,java]
  16. ....
  17. public class OpeningUIInPopup extends UI {
  18. @Override
  19. protected void init(VaadinRequest request) {
  20. Button popupButton = new Button("Open popup with MyPopupUI");
  21. BrowserWindowOpener popupOpener = new BrowserWindowOpener(MyPopupUI.class);
  22. popupOpener.setFeatures("height=300,width=300");
  23. popupOpener.extend(popupButton);
  24. // Add a parameter
  25. popupOpener.setParameter("foo", "bar");
  26. // Set a fragment
  27. popupOpener.setUriFragment("myfragment");
  28. setContent(popupButton);
  29. }
  30. }
  31. public class MyPopupUI extends UI {
  32. @Override
  33. protected void init(VaadinRequest request) {
  34. setContent(new Label("This is MyPopupUI where parameter foo="
  35. + request.getParameter("foo") + " and fragment is set to "
  36. + getPage().getUriFragment()));
  37. }
  38. }
  39. ....
  40. In this example, a `Button` is created and extended with a
  41. `BrowserWindowOpener`. Furthermore, the size of the popup window is
  42. defined. See
  43. https://developer.mozilla.org/en-US/docs/DOM/window.open#Position_and_size_features
  44. for a description of the commonly supported features. If you don't
  45. define any features, the browser will use its default setting which
  46. usually makes it open a new tab instead of opening a popup window.
  47. The `BrowserWindowOpener` can also be used to open a `Resource` or any
  48. URL that you define using different constructors.