com.vaadin.server
Class AbstractJavaScriptExtension

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

public abstract class AbstractJavaScriptExtension
extends AbstractExtension

Base class for Extensions with all client-side logic implemented using JavaScript.

When a new JavaScript extension is initialized in the browser, the framework will look for a globally defined JavaScript function that will initialize the extension. The name of the initialization function is formed by replacing . with _ in the name of the server-side class. If no such function is defined, each super class is used in turn until a match is found. The framework will thus first attempt with com_example_MyExtension for the server-side com.example.MyExtension extends AbstractJavaScriptExtension class. If MyExtension instead extends com.example.SuperExtension , then com_example_SuperExtension will also be attempted if com_example_MyExtension has not been defined.

The initialization function will be called with this pointing to a connector wrapper object providing integration to Vaadin with the following functions:

The connector wrapper also supports these special functions:

Values in the Shared State and in RPC calls are converted between Java and JavaScript using the following conventions:

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Constructor Summary
AbstractJavaScriptExtension()
           
 
Method Summary
protected  void addFunction(java.lang.String functionName, JavaScriptFunction function)
          Register a JavaScriptFunction that can be called from the JavaScript using the provided name.
protected  void callFunction(java.lang.String name, java.lang.Object... arguments)
          Invoke a named function that the connector JavaScript has added to the JavaScript connector wrapper object.
protected  com.vaadin.shared.JavaScriptExtensionState getState()
          Returns the shared state for this connector.
protected
<T extends com.vaadin.shared.communication.ServerRpc>
void
registerRpc(T implementation, java.lang.Class<T> rpcInterfaceType)
          Registers an RPC interface implementation for this component.
 
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getSupportedParentType, remove, setParent
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getParent, getResource, getRpcManager, getRpcProxy, getSession, getState, getStateType, getUI, handleConnectorRequest, hasListeners, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getParent, getRpcManager, getStateType, getUI, handleConnectorRequest, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

Constructor Detail

AbstractJavaScriptExtension

public AbstractJavaScriptExtension()
Method Detail

registerRpc

protected <T extends com.vaadin.shared.communication.ServerRpc> void registerRpc(T implementation,
                                                                                 java.lang.Class<T> rpcInterfaceType)
Description copied from class: AbstractClientConnector
Registers an RPC interface implementation for this component. A component can listen to multiple RPC interfaces, and subclasses can register additional implementations.

Overrides:
registerRpc in class AbstractClientConnector
Parameters:
implementation - RPC interface implementation
rpcInterfaceType - RPC interface class for which the implementation should be registered

addFunction

protected void addFunction(java.lang.String functionName,
                           JavaScriptFunction function)
Register a JavaScriptFunction that can be called from the JavaScript using the provided name. A JavaScript function with the provided name will be added to the connector wrapper object (initially available as this). Calling that JavaScript function will cause the call method in the registered JavaScriptFunction to be invoked with the same arguments.

Parameters:
functionName - the name that should be used for client-side callback
function - the JavaScriptFunction object that will be invoked when the JavaScript function is called

callFunction

protected void callFunction(java.lang.String name,
                            java.lang.Object... arguments)
Invoke a named function that the connector JavaScript has added to the JavaScript connector wrapper object. The arguments should only contain data types that can be represented in JavaScript including primitives, their boxed types, arrays, String, List, Set, Map, Connector and JavaBeans.

Parameters:
name - the name of the function
arguments - function arguments

getState

protected com.vaadin.shared.JavaScriptExtensionState 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.


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