Class AbstractJavaScriptRenderer<T>

  • All Implemented Interfaces:
    MethodEventSource, ClientConnector, Extension, Connector, Renderer<T>, Serializable

    public abstract class AbstractJavaScriptRenderer<T>
    extends Grid.AbstractRenderer<T>
    Base class for Renderers with all client-side logic implemented using JavaScript.

    When a new JavaScript renderer is initialized in the browser, the framework will look for a globally defined JavaScript function that will initialize the renderer. 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_MyRenderer for the server-side com.example.MyRenderer extends AbstractJavaScriptRenderer class. If MyRenderer instead extends com.example.SuperRenderer , then com_example_SuperRenderer will also be attempted if com_example_MyRenderer has not been defined.

    In addition to the general JavaScript extension functionality explained in AbstractJavaScriptExtension, this class also provides some functionality specific for renderers.

    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;. In addition to the extension functions described for AbstractJavaScriptExtension, the connector wrapper object also provides this function:

    The connector wrapper also supports these special functions that can be implemented by the connector:

    The cell object passed to functions defined by the renderer has these properties:

    • element - The DOM element corresponding to this cell. Readonly.
    • rowIndex - The current index of the row of this cell. Readonly.
    • columnIndex - The current index of the column of this cell. Readonly.
    • colSpan - The number of columns spanned by this cell. Only supported in the object passed to the render function - other functions should not use the property. Readable and writable.
    Since:
    7.4
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • AbstractJavaScriptRenderer

        protected AbstractJavaScriptRenderer​(Class<T> presentationType,
                                             String nullRepresentation)
      • AbstractJavaScriptRenderer

        protected AbstractJavaScriptRenderer​(Class<T> presentationType)
    • Method Detail

      • registerRpc

        protected <R extends ServerRpc> void registerRpc​(R implementation,
                                                         Class<R> 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​(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​(String name,
                                    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 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.