com.vaadin.ui
Class JavaScript

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.server.AbstractExtension
          extended by com.vaadin.ui.JavaScript
All Implemented Interfaces:
MethodEventSource, ClientConnector, Extension, com.vaadin.shared.Connector, java.io.Serializable

public class JavaScript
extends AbstractExtension

Provides access to JavaScript functionality in the web browser. To get an instance of JavaScript, either use Page.getJavaScript() or JavaScript.getCurrent() as a shorthand for getting the JavaScript object corresponding to the current Page.

Since:
7.0.0
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
static interface JavaScript.JavaScriptCallbackRpc
           
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Constructor Summary
JavaScript()
          Creates a new JavaScript object.
 
Method Summary
 void addFunction(java.lang.String name, JavaScriptFunction function)
          Add a new function to the global JavaScript namespace (i.e.
static void eval(java.lang.String script)
          Executes the given JavaScript code in the browser.
 void execute(java.lang.String script)
          Executes the given JavaScript code in the browser.
static JavaScript getCurrent()
          Get the JavaScript object for the current Page, or null if there is no current page.
protected  com.vaadin.shared.extension.javascriptmanager.JavaScriptManagerState getState()
          Returns the shared state for this connector.
 void remove()
          JavaScript is not designed to be removed.
 void removeFunction(java.lang.String name)
          Removes a JavaScripFunction from the browser's global JavaScript namespace.
 
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getParent, getSupportedParentType, setParent
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getState, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

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 com.vaadin.shared.extension.javascriptmanager.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(java.lang.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(java.lang.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(java.lang.String script)
Executes the given JavaScript code in the browser.

Parameters:
script - The JavaScript code to run.

eval

public static void eval(java.lang.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()

remove

public void remove()
JavaScript is not designed to be removed.

Specified by:
remove in interface Extension
Overrides:
remove in class AbstractExtension
Throws:
java.lang.UnsupportedOperationException - when invoked


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.