com.vaadin.ui
Class JavaScript

java.lang.Object
  extended by com.vaadin.terminal.AbstractClientConnector
      extended by com.vaadin.terminal.AbstractExtension
          extended by com.vaadin.ui.JavaScript
All Implemented Interfaces:
Extension, Connector, ClientConnector, RpcTarget, 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
Version:
7.0.0.alpha3
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
static interface JavaScript.JavaScriptCallbackRpc
           
 
Constructor Summary
JavaScript()
          Creates a new JavaScript object.
 
Method Summary
 void addCallback(String name, JavaScriptCallback callback)
          Add a new function to the global JavaScript namespace (i.e.
static void eval(String script)
          Executes the given JavaScript code in the browser.
 void execute(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.
 JavaScriptManagerState getState()
          Gets the current shared state of the connector.
 void removeCallback(String name)
          Removes a JavaScripCallback from the browser's global JavaScript namespace.
 void removeFromTarget()
          JavaScript is not designed to be removed.
 
Methods inherited from class com.vaadin.terminal.AbstractExtension
extend, getSupportedParentType, setParent
 
Methods inherited from class com.vaadin.terminal.AbstractClientConnector
addExtension, addMethodInvocationToQueue, attach, createState, detach, getAllChildrenIterable, getApplication, getConnectorId, getExtensions, getParent, getRoot, getRpcManager, getRpcProxy, getStateType, isConnectorEnabled, registerRpc, registerRpc, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.terminal.gwt.server.ClientConnector
attach, detach, getExtensions, getParent, getRoot, getStateType, isConnectorEnabled, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls
 
Methods inherited from interface com.vaadin.terminal.gwt.client.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.terminal.gwt.server.RpcTarget
getRpcManager
 

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

public JavaScriptManagerState getState()
Description copied from interface: Connector
Gets the current shared state of the connector.

Specified by:
getState in interface Connector
Overrides:
getState in class AbstractClientConnector
Returns:
state The shared state object. Can be any sub type of SharedState. Never null.

addCallback

public void addCallback(String name,
                        JavaScriptCallback callback)
Add a new function to the global JavaScript namespace (i.e. the window object). The call method in the passed JavaScriptCallback object will be invoked with the same parameters whenever the JavaScript function is called in the browser. A callback added with the name "myCallback" can thus be invoked with the following JavaScript code: window.myCallback(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 callback function should get in the global JavaScript namespace.
callback - the JavaScriptCallback that will be invoked if the JavaScript function is called.

removeCallback

public void removeCallback(String name)
Removes a JavaScripCallback from the browser's global JavaScript namespace. If the name contains dots and intermediate were created by addCallback(String, JavaScriptCallback)addCallback, these objects will not be removed when the callback is removed.

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()

removeFromTarget

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

Overrides:
removeFromTarget in class AbstractExtension
Throws:
UnsupportedOperationException - when invoked


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