com.vaadin.flow.component.page.

Class Page

  • All Implemented Interfaces:

    Serializable


    public class Page
    extends Object
    implements Serializable

    Represents the web page open in the browser, containing the UI it is connected to.

    Since:

    1.0

    Author:

    Vaadin Ltd

    See Also:

    Serialized Form

    • Constructor Detail

      • Page

        public Page(UI ui)

        Creates a page instance for the given UI.

        Parameters:

        ui - the UI that this page instance is connected to

    • Method Detail

      • setTitle

        public void setTitle(String title)

        Sets the page title. The title is displayed by the browser e.g. as the title of the browser window or tab.

        To clear the page title, use an empty string.

        Parameters:

        title - the page title to set, not null

      • addStyleSheet

        public void addStyleSheet(String url)

        Adds the given style sheet to the page and ensures that it is loaded successfully.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        For component related style sheet dependencies, you should use the @StyleSheet annotation.

        Is is guaranteed that style sheet will be loaded before the first page load. For more options, refer to addStyleSheet(String, LoadMode)

        Parameters:

        url - the URL to load the style sheet from, not null

      • addStyleSheet

        public void addStyleSheet(String url,
                                  LoadMode loadMode)

        Adds the given style sheet to the page and ensures that it is loaded successfully.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        For component related style sheet dependencies, you should use the @StyleSheet annotation.

        Parameters:

        url - the URL to load the style sheet from, not null

        loadMode - determines dependency load mode, refer to LoadMode for details

      • addJavaScript

        public void addJavaScript(String url)

        Adds the given JavaScript to the page and ensures that it is loaded successfully.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        For component related JavaScript dependencies, you should use the @JavaScript annotation.

        Is is guaranteed that script will be loaded before the first page load. For more options, refer to addJavaScript(String, LoadMode)

        Parameters:

        url - the URL to load the JavaScript from, not null

      • addJavaScript

        public void addJavaScript(String url,
                                  LoadMode loadMode)

        Adds the given JavaScript to the page and ensures that it is loaded successfully.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        For component related JavaScript dependencies, you should use the @JavaScript annotation.

        Parameters:

        url - the URL to load the JavaScript from, not null

        loadMode - determines dependency load mode, refer to LoadMode for details

      • addJsModule

        public void addJsModule(String url)

        Adds the given external JavaScript module to the page and ensures that it is loaded successfully.

        If the JavaScript modules do not need to be added dynamically, you should use the @JsModule annotation instead.

        Parameters:

        url - the URL to load the JavaScript module from, not null

      • addJsModule

        @Deprecated
        public void addJsModule(String url,
                                            LoadMode loadMode)

        Deprecated. LoadMode is not functional with external JavaScript modules, as those are loaded as deferred due to type=module in scrip tag. Use addJsModule(String) instead.

        Adds the given external JavaScript module to the page and ensures that it is loaded successfully.

        If the JavaScript modules do not need to be added dynamically, you should use the @JsModule annotation instead.

        Parameters:

        url - the URL to load the JavaScript module from, not null

        loadMode - this argument is ignored and the loadMode will always be LoadMode.EAGER since LoadMode doesn't work with Dependency.Type.JS_MODULE. See Deprecated section for more details.

      • addHtmlImport

        public void addHtmlImport(String url)

        In compatibility mode (or Flow 1.x), adds the given HTML import to the page and ensures that it is loaded successfully. In normal mode (Flow 2.x with npm support), throws an UnsupportedOperationException.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        Is is guaranteed that html import will be loaded before the first page load. For more options, refer to addHtmlImport(String, LoadMode)

        Parameters:

        url - the URL to load the HTML import from, not null

        Throws:

        UnsupportedOperationException - if called outside of compatibility mode.

      • addHtmlImport

        public void addHtmlImport(String url,
                                  LoadMode loadMode)

        In compatibility mode (or Flow 1.x), adds the given HTML import to the page and ensures that it is loaded successfully. In normal mode (Flow 2.x with npm support), throws an UnsupportedOperationException.

        Relative URLs are interpreted as relative to the configured frontend directory location. You can prefix the URL with context:// to make it relative to the context path or use an absolute URL to refer to files outside the frontend directory.

        Parameters:

        url - the URL to load the HTML import from, not null

        loadMode - determines dependency load mode, refer to LoadMode for details

        Throws:

        UnsupportedOperationException - if called outside of compatibility mode.

      • addDynamicImport

        public void addDynamicImport(String expression)

        Adds a dynamic import using a JavaScript expression which is supposed to return a JavaScript Promise.

        No change will be applied on the client side until resulting Promise of the expression is completed. It behaves like other dependencies (addJavaScript(String), addJsModule(String), etc.)

        Parameters:

        expression - the JavaScript expression which return a Promise

        See Also:

        addHtmlImport(String)

      • executeJavaScript

        @Deprecated
        public Page.ExecutionCanceler executeJavaScript(String expression,
                                                                    Serializable... parameters)

        Deprecated. Use executeJs(String,Serializable...) instead since it also allows getting return value back.

        Asynchronously runs the given JavaScript expression in the browser. The given parameters will be available to the expression as variables named $0, $1, and so on. Supported parameter types are:

        • String
        • Integer
        • Double
        • Boolean
        • JsonValue
        • Element (will be sent as null if the server-side element instance is not attached when the invocation is sent to the client)
        Note that the parameter variables can only be used in contexts where a JavaScript variable can be used. You should for instance do 'prefix' + $0 instead of 'prefix$0' and value[$0] instead of value.$0 since JavaScript variables aren't evaluated inside strings or property names.

        Parameters:

        expression - the JavaScript expression to invoke

        parameters - parameters to pass to the expression

        Returns:

        a callback for canceling the execution if not yet sent to browser

      • executeJs

        public PendingJavaScriptResult executeJs(String expression,
                                                 Serializable... parameters)

        Asynchronously runs the given JavaScript expression in the browser.

        The returned PendingJavaScriptResult can be used to retrieve any return value from the JavaScript expression. If no return value handler is registered, the return value will be ignored.

        The given parameters will be available to the expression as variables named $0, $1, and so on. Supported parameter types are:

        • String
        • Integer
        • Double
        • Boolean
        • JsonValue
        • Element (will be sent as null if the server-side element instance is not attached when the invocation is sent to the client)
        Note that the parameter variables can only be used in contexts where a JavaScript variable can be used. You should for instance do 'prefix' + $0 instead of 'prefix$0' and value[$0] instead of value.$0 since JavaScript variables aren't evaluated inside strings or property names.

        Parameters:

        expression - the JavaScript expression to invoke

        parameters - parameters to pass to the expression

        Returns:

        a pending result that can be used to get a value returned from the expression

      • getHistory

        public History getHistory()

        Gets a representation of window.history for this page.

        Returns:

        the history representation

      • reload

        public void reload()

        Reloads the page in the browser.

      • open

        public void open(String url)

        Opens the given url in a new tab.

        Parameters:

        url - the URL to open.

      • setLocation

        public void setLocation(String uri)

        Navigates this page to the given URI. The contents of this page in the browser is replaced with whatever is returned for the given URI.

        Parameters:

        uri - the URI to show

      • setLocation

        public void setLocation(URI uri)

        Navigates this page to the given URI. The contents of this page in the browser is replaced with whatever is returned for the given URI.

        Parameters:

        uri - the URI to show

      • retrieveExtendedClientDetails

        public void retrieveExtendedClientDetails(Page.ExtendedClientDetailsReceiver receiver)

        Obtain extended client side details, such as time screen and time zone information, via callback. If already obtained, the callback is called directly. Otherwise, a client-side roundtrip will be carried out.

        Parameters:

        receiver - the callback to which the details are provided