Package com.vaadin.ui
Class JavaScript
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.JavaScript
-
- All Implemented Interfaces:
MethodEventSource,ClientConnector,Extension,Connector,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
Nested Classes Modifier and Type Class Description static interfaceJavaScript.JavaScriptCallbackRpc-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
-
Constructor Summary
Constructors Constructor Description JavaScript()Creates a new JavaScript object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFunction(String name, JavaScriptFunction function)Add a new function to the global JavaScript namespace (i.e.static voideval(String script)Executes the given JavaScript code in the browser.voidexecute(String script)Executes the given JavaScript code in the browser.static JavaScriptgetCurrent()Get the JavaScript object for the current Page, or null if there is no current page.protected JavaScriptManagerStategetState()Returns the shared state for this connector.protected JavaScriptManagerStategetState(boolean markAsDirty)Returns the shared state for this connector.voidremove()JavaScript is not designed to be removed.voidremoveFunction(String name)Removes a JavaScriptFunction 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, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
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
-
-
-
-
Method Detail
-
getState
protected JavaScriptManagerState getState()
Description copied from class:AbstractClientConnectorReturns 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:
getStatein classAbstractClientConnector- Returns:
- The shared state for this connector. Never null.
-
getState
protected JavaScriptManagerState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractClientConnector- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
addFunction
public void addFunction(String name, JavaScriptFunction function)
Add a new function to the global JavaScript namespace (i.e. the window object). Thecallmethod in the passedJavaScriptFunctionobject 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 JavaScriptFunction from the browser's global JavaScript namespace. If the name contains dots and intermediate objects were created byaddFunction(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
nullif there is no current page. - See Also:
Page.getCurrent()
-
remove
public void remove()
JavaScript is not designed to be removed.- Specified by:
removein interfaceExtension- Overrides:
removein classAbstractExtension- Throws:
UnsupportedOperationException- when invoked
-
-