Class PageUtils

java.lang.Object
com.vaadin.featurepack.util.PageUtils

public class PageUtils extends Object
Utility class for Vaadin 7/8 Page API.
  • Constructor Details

    • PageUtils

      public PageUtils()
  • Method Details

    • getWebBrowser

      public static com.vaadin.flow.server.WebBrowser getWebBrowser()
    • getWebBrowser

      public static com.vaadin.flow.server.WebBrowser getWebBrowser(com.vaadin.flow.component.page.Page p)
    • getBrowserWindowHeight

      public static int getBrowserWindowHeight()
      Gets the last known height of the browser window in which this UI resides.
      Returns:
      the browser window height in pixels
    • getBrowserWindowHeight

      public static int getBrowserWindowHeight(com.vaadin.flow.component.page.Page p)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • getBrowserWindowWidth

      public static int getBrowserWindowWidth()
      Gets the last known width of the browser window in which this uI resides.
      Returns:
      the browser window width in pixels
    • getBrowserWindowWidth

      public static int getBrowserWindowWidth(com.vaadin.flow.component.page.Page p)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • getUriFragment

      public static String getUriFragment()
      Gets the currently set URI fragment.

      Returns null if there is no fragment and an empty string if there is an empty fragment.

      To listen to changes in fragment, hook a PageUtils.UriFragmentChangedEvent.

      Returns:
      the current fragment in browser location URI.
      See Also:
    • getUriFragment

      public static String getUriFragment(com.vaadin.flow.component.page.Page p)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • setUriFragment

      public static void setUriFragment(String newUriFragment)
      Sets URI fragment. This method fires a PageUtils.UriFragmentChangedEvent
      Parameters:
      newUriFragment - id of the new fragment
      See Also:
    • setUriFragment

      public static void setUriFragment(com.vaadin.flow.component.page.Page p, String newUriFragment)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • addUriFragmentChangedListener

      public static void addUriFragmentChangedListener(PageUtils.UriFragmentChangedListener listener)
      Adds a listener that gets notified every time the URI fragment of this page is changed. Please note that the initial URI fragment has already been set when a new UI is initialized, so there will not be any initial event for listeners added during UI#init(VaadinRequest).
      Parameters:
      listener - the URI fragment listener to add
      See Also:
    • addUriFragmentChangedListener

      public static void addUriFragmentChangedListener(com.vaadin.flow.component.page.Page p, PageUtils.UriFragmentChangedListener listener)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • initHashchangeEventListener

      public static void initHashchangeEventListener()
      Initializes the 'hashchange' event listener for the current UI. Flow is not keeping track of fragment on server side by default. setUriFragment(String) and addUriFragmentChangedListener(UriFragmentChangedListener) calls this by default.
    • removeUriFragmentChangedListener

      public static void removeUriFragmentChangedListener(PageUtils.UriFragmentChangedListener listener)
      Removes a URI fragment listener that was previously added to this page.
      Parameters:
      listener - the URI fragment listener to remove
      See Also:
    • removeUriFragmentChangedListener

      public static void removeUriFragmentChangedListener(com.vaadin.flow.component.page.Page p, PageUtils.UriFragmentChangedListener listener)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • setUriFragment

      public static void setUriFragment(String newUriFragment, boolean fireEvents)
      Sets the fragment part in the current location URI. Optionally fires a PageUtils.UriFragmentChangedEvent.

      The fragment is the optional last component of a URI, prefixed with a hash sign ("#").

      Passing an empty string as newFragment sets an empty fragment (a trailing "#" in the URI.) Passing null if there is already a non-null fragment will leave a trailing # in the URI since removing it would cause the browser to reload the page. This is not fully consistent with the semantics of URI.

      Parameters:
      newUriFragment - The new fragment.
      fireEvents - true to fire event
      See Also:
    • setUriFragment

      public static void setUriFragment(com.vaadin.flow.component.page.Page p, String newUriFragment, boolean fireEvents)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • open

      public static void open(String url, String windowName)
      Opens the given url in a window with the given name. Equivalent to open (url, windowName, true) .

      The supplied windowName is used as the target name in a window.open call in the client. This means that special values such as "_blank", "_self", "_top", "_parent" have special meaning. An empty or null window name is also a special case.

      "", null and "_self" as windowName all causes the URL to be opened in the current window, replacing any old contents. For downloadable content you should avoid "_self" as "_self" causes the client to skip rendering of any other changes as it considers them irrelevant (the page will be replaced by the response from the URL). This can speed up the opening of a URL, but it might also put the client side into an inconsistent state if the window content is not completely replaced e.g., if the URL is downloaded instead of displayed in the browser.

      "_blank" as windowName causes the URL to always be opened in a new window or tab (depends on the browser and browser settings).

      "_top" and "_parent" as windowName works as specified by the HTML standard.

      Any other windowName will open the URL in a window with that name, either by opening a new window/tab in the browser or by replacing the contents of an existing window with that name.

      Please note that opening a popup window in this way may be blocked by the browser's popup-blocker because the new browser window is opened when processing a response from the server. To avoid this, you should instead use Link for opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.

      Parameters:
      url - the URL to open.
      windowName - the name of the window.
    • open

      public static void open(com.vaadin.flow.component.page.Page p, String url, String windowName)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • open

      public static void open(String url, String windowName, boolean tryToOpenAsPopup)
      Opens the given url in a window with the given name. Equivalent to open (url, windowName, true) .

      The supplied windowName is used as the target name in a window.open call in the client. This means that special values such as "_blank", "_self", "_top", "_parent" have special meaning. An empty or null window name is also a special case.

      "", null and "_self" as windowName all causes the URL to be opened in the current window, replacing any old contents. For downloadable content you should avoid "_self" as "_self" causes the client to skip rendering of any other changes as it considers them irrelevant (the page will be replaced by the response from the URL). This can speed up the opening of a URL, but it might also put the client side into an inconsistent state if the window content is not completely replaced e.g., if the URL is downloaded instead of displayed in the browser.

      "_blank" as windowName causes the URL to always be opened in a new window or tab (depends on the browser and browser settings).

      "_top" and "_parent" as windowName works as specified by the HTML standard.

      Any other windowName will open the URL in a window with that name, either by opening a new window/tab in the browser or by replacing the contents of an existing window with that name.

      Please note that opening a popup window in this way may be blocked by the browser's popup-blocker because the new browser window is opened when processing a response from the server. To avoid this, you should instead use Link for opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.

      Parameters:
      url - the URL to open.
      windowName - the name of the window.
      tryToOpenAsPopup - Whether to try to force the resource to be opened in a new window
    • open

      public static void open(com.vaadin.flow.component.page.Page p, String url, String windowName, boolean tryToOpenAsPopup)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.
    • open

      public static void open(String url, String windowName, int width, int height, BorderStyle border)
      Opens the given URL in a window with the given size, border and name. For more information on the meaning of windowName, see open(String, String).

      Please note that opening a popup window in this way may be blocked by the browser's popup-blocker because the new browser window is opened when processing a response from the server. To avoid this, you should instead use Link for opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.

      Parameters:
      url - the URL to open.
      windowName - the name of the window.
      width - the width of the window in pixels
      height - the height of the window in pixels
      border - the border style of the window.
    • open

      public static void open(com.vaadin.flow.component.page.Page p, String url, String windowName, int width, int height, BorderStyle border)
      Method to retain the Page returning expression after transformation. Does nothing on Page parameter.