com.vaadin.ui
Class AbstractJavaScriptComponent

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractJavaScriptComponent
All Implemented Interfaces:
ContextClickEvent.ContextClickNotifier, MethodEventSource, ClientConnector, Sizeable, com.vaadin.shared.Connector, Component, java.io.Serializable

public abstract class AbstractJavaScriptComponent
extends AbstractComponent

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

When a new JavaScript component is initialized in the browser, the framework will look for a globally defined JavaScript function that will initialize the component. 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_MyComponent for the server-side com.example.MyComponent extends AbstractJavaScriptComponent class. If MyComponent instead extends com.example.SuperComponent , then com_example_SuperComponent will also be attempted if com_example_MyComponent has not been defined.

JavaScript components have a very simple GWT widget ( com.vaadin.client.ui.JavaScriptWidget ) just consisting of a div element to which the JavaScript code should initialize its own user interface.

The initialization function will be called with this pointing to a connector wrapper object providing integration to Vaadin. Please note that in JavaScript, this is not necessarily defined inside callback functions and it might therefore be necessary to assign the reference to a separate variable, e.g. var self = this;. The following functions are provided by the connector wrapper object:

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.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Field Summary
 
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
AbstractJavaScriptComponent()
           
 
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.ui.JavaScriptComponentState getState()
          Returns the shared state bean with information to be sent from the server to the client.
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.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getState, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, readDesign, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined, writeDesign
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, 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.ui.Component
getUI
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

Constructor Detail

AbstractJavaScriptComponent

public AbstractJavaScriptComponent()
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 function
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 can be any boxed primitive type, String, JsonValue or arrays of any other supported type. Complex types (e.g. List, Set, Map, Connector or any JavaBean type) must be explicitly serialized to a JsonValue before sending. This can be done either with JsonCodec.encode(Object, JsonValue, java.lang.reflect.Type, com.vaadin.ui.ConnectorTracker) or using the factory methods in Json.

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

getState

protected com.vaadin.shared.ui.JavaScriptComponentState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractComponent
Returns:
updated component shared state


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