Package com.vaadin.ui

Class JavaScript

    • Constructor Detail

      • JavaScript

        public JavaScript()
        Creates a new JavaScript object. You should typically not this, but instead use the JavaScript object already associated with your Page object.
    • Method Detail

      • getState

        protected JavaScriptManagerState getState()
        Description copied from class: AbstractClientConnector
        Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.

        As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use getState(false) to avoid marking the connector as dirty.

        Overrides:
        getState in class AbstractClientConnector
        Returns:
        The shared state for this connector. Never null.
      • addFunction

        public void addFunction​(String name,
                                JavaScriptFunction function)
        Add a new function to the global JavaScript namespace (i.e. the window object). The call method in the passed JavaScriptFunction object will be invoked with the same parameters whenever the JavaScript function is called in the browser. A function added with the name "myFunction" can thus be invoked with the following JavaScript code: window.myFunction(argument1, argument2). If the name parameter contains dots, simple objects are created on demand to allow calling the function using the same name (e.g. window.myObject.myFunction).
        Parameters:
        name - the name that the function should get in the global JavaScript namespace.
        function - the JavaScriptFunction that will be invoked if the JavaScript function is called.
      • removeFunction

        public void removeFunction​(String name)
        Removes a JavaScripFunction from the browser's global JavaScript namespace. If the name contains dots and intermediate objects were created by addFunction(String, JavaScriptFunction), these objects will not be removed by this method.
        Parameters:
        name - the name of the callback to remove
      • execute

        public void execute​(String script)
        Executes the given JavaScript code in the browser.
        Parameters:
        script - The JavaScript code to run.
      • eval

        public static void eval​(String script)
        Executes the given JavaScript code in the browser.
        Parameters:
        script - The JavaScript code to run.
      • getCurrent

        public static JavaScript getCurrent()
        Get the JavaScript object for the current Page, or null if there is no current page.
        Returns:
        the JavaScript object corresponding to the current Page, or null if there is no current page.
        See Also:
        Page.getCurrent()