Class AbstractClientConnector

    • Constructor Detail

      • AbstractClientConnector

        public AbstractClientConnector()
    • Method Detail

      • addAttachListener

        public com.vaadin.shared.Registration addAttachListener​(ClientConnector.AttachListener listener)
        Description copied from interface: ClientConnector
        Add a listener for connector attach events.
        Specified by:
        addAttachListener in interface ClientConnector
        Parameters:
        listener - an AttachListener implementation
        Returns:
        Registration for unregistering the listener
      • addDetachListener

        public com.vaadin.shared.Registration addDetachListener​(ClientConnector.DetachListener listener)
        Description copied from interface: ClientConnector
        Add a listener for connector detach events.
        Specified by:
        addDetachListener in interface ClientConnector
        Parameters:
        listener - an AttachListener implementation
        Returns:
        Registration for unregistering the listener
      • registerRpc

        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. A component can listen to multiple RPC interfaces, and subclasses can register additional implementations.
        Parameters:
        implementation - RPC interface implementation
        rpcInterfaceType - RPC interface class for which the implementation should be registered
        Since:
        7.0
      • registerRpc

        protected <T extends com.vaadin.shared.communication.ServerRpc> void registerRpc​(T implementation)
        Registers an RPC interface implementation for this component. A component can listen to multiple RPC interfaces, and subclasses can register additional implementations.
        Parameters:
        implementation - RPC interface implementation. Also used to deduce the type.
        Since:
        7.0
      • getState

        protected com.vaadin.shared.communication.SharedState getState()
        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.

        Returns:
        The shared state for this connector. Never null.
      • getState

        protected com.vaadin.shared.communication.SharedState getState​(boolean markAsDirty)
        Returns the shared state for this connector.
        Parameters:
        markAsDirty - true if the connector should automatically be marked dirty, false otherwise
        Returns:
        The shared state for this connector. Never null.
        See Also:
        getState()
      • createState

        protected com.vaadin.shared.communication.SharedState createState()
        Creates the shared state bean to be used in server to client communication.

        By default a state object of the defined return type of getState() is created. Subclasses can override this method and return a new instance of the correct state class but this should rarely be necessary.

        No configuration of the values of the state should be performed in createState().

        Returns:
        new shared state object
        Since:
        7.0
      • getStateType

        public java.lang.Class<? extends com.vaadin.shared.communication.SharedState> getStateType()
        Description copied from interface: ClientConnector
        Returns the type of the shared state for this connector.
        Specified by:
        getStateType in interface ClientConnector
        Returns:
        The type of the state. Must never return null.
      • getRpcProxy

        protected <T extends com.vaadin.shared.communication.ClientRpc> T getRpcProxy​(java.lang.Class<T> rpcInterface)
        Returns an RPC proxy for a given server to client RPC interface for this component. TODO more javadoc, subclasses, ...
        Parameters:
        rpcInterface - RPC interface type
        Since:
        7.0
      • addMethodInvocationToQueue

        protected void addMethodInvocationToQueue​(java.lang.String interfaceName,
                                                  java.lang.reflect.Method method,
                                                  java.lang.Object[] parameters)
        For internal use: adds a method invocation to the pending RPC call queue.
        Parameters:
        interfaceName - RPC interface name
        method - RPC method
        parameters - RPC all parameters
        Since:
        7.0
      • getRpcManager

        public ServerRpcManager<?> getRpcManager​(java.lang.String rpcInterfaceName)
        Description copied from interface: ClientConnector
        Returns the RPC manager instance to use when receiving calls for an RPC interface.
        Specified by:
        getRpcManager in interface ClientConnector
        Parameters:
        rpcInterfaceName - name of the interface for which the call was made
        Returns:
        ServerRpcManager or null if none found for the interface
      • retrievePendingRpcCalls

        public java.util.List<ClientMethodInvocation> retrievePendingRpcCalls()
        Description copied from interface: ClientConnector
        Returns the list of pending server to client RPC calls and clears the list.
        Specified by:
        retrievePendingRpcCalls in interface ClientConnector
        Returns:
        an unmodifiable ordered list of pending server to client method calls (not null)
      • getConnectorId

        public java.lang.String getConnectorId()
        Specified by:
        getConnectorId in interface com.vaadin.shared.Connector
      • getSession

        protected VaadinSession getSession()
        Finds the VaadinSession to which this connector belongs. If the connector has not been attached, null is returned.
        Returns:
        The connector's session, or null if not attached
      • getUI

        public UI getUI()
        Finds a UI ancestor of this connector. null is returned if no UI ancestor is found (typically because the connector is not attached to a proper hierarchy).
        Specified by:
        getUI in interface ClientConnector
        Returns:
        the UI ancestor of this connector, or null if none is found.
      • markAsDirtyRecursive

        public void markAsDirtyRecursive()
        Description copied from interface: ClientConnector
        Causes this connector and all connectors below it to be marked as dirty.

        This should only be used in special cases, e.g when the state of a descendant depends on the state of an ancestor.

        Specified by:
        markAsDirtyRecursive in interface ClientConnector
        See Also:
        ClientConnector.markAsDirty()
      • getAllChildrenIterable

        public static java.lang.Iterable<? extends ClientConnector> getAllChildrenIterable​(ClientConnector connector)
        Get an Iterable for iterating over all child connectors, including both extensions and child components.
        Parameters:
        connector - the connector to get children for
        Returns:
        an Iterable giving all child connectors.
      • getExtensions

        public java.util.Collection<Extension> getExtensions()
        Description copied from interface: ClientConnector
        Get a read-only collection of all extensions attached to this connector.
        Specified by:
        getExtensions in interface ClientConnector
        Returns:
        a collection of extensions
      • addExtension

        protected void addExtension​(Extension extension)
        Add an extension to this connector. This method is protected to allow extensions to select which targets they can extend.
        Parameters:
        extension - the extension to add
      • removeExtension

        public void removeExtension​(Extension extension)
        Description copied from interface: ClientConnector
        Remove an extension from this connector.
        Specified by:
        removeExtension in interface ClientConnector
        Parameters:
        extension - the extension to remove.
      • isAttached

        public boolean isAttached()
        Description copied from interface: ClientConnector
        Checks if the connector is attached to a VaadinSession.
        Specified by:
        isAttached in interface ClientConnector
        Returns:
        true if the connector is attached to a session, false otherwise
      • attach

        public void attach()
        Description copied from interface: ClientConnector
        Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).

        The caller of this method is Component.setParent(HasComponents) if the parent is itself already attached to the session. If not, the parent will call the ClientConnector.attach() for all its children when it is attached to the session. This method is always called before the connector's data is sent to the client-side for the first time.

        The attachment logic is implemented in AbstractClientConnector.

        Specified by:
        attach in interface ClientConnector
      • isConnectorEnabled

        public boolean isConnectorEnabled()
        Description copied from interface: ClientConnector
        Checks if the communicator is enabled. An enabled communicator is allowed to receive messages from its counter-part.
        Specified by:
        isConnectorEnabled in interface ClientConnector
        Returns:
        true if the connector can receive messages, false otherwise
      • beforeClientResponse

        public void beforeClientResponse​(boolean initial)
        Description copied from interface: ClientConnector
        Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.
        Specified by:
        beforeClientResponse in interface ClientConnector
        Parameters:
        initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.
      • handleConnectorRequest

        public boolean handleConnectorRequest​(VaadinRequest request,
                                              VaadinResponse response,
                                              java.lang.String path)
                                       throws java.io.IOException
        Description copied from interface: ClientConnector
        Handle a request directed to this connector. This can be used by connectors to dynamically generate a response and it is also used internally when serving ConnectorResources.

        Requests to /APP/connector/[ui id]/[connector id]/ are routed to this method with the remaining part of the requested path available in the path parameter.

        NOTE that the session is not locked when this method is called. It is the responsibility of the connector to ensure that the session is locked while handling state or other session related data. For best performance the session should be unlocked before writing a large response to the client.

        Specified by:
        handleConnectorRequest in interface ClientConnector
        Parameters:
        request - the request that should be handled
        response - the response object to which the response should be written
        path - the requested relative path
        Returns:
        true if the request has been handled, false if no response has been written.
        Throws:
        java.io.IOException - if there is a problem generating a response.
      • getResource

        protected Resource getResource​(java.lang.String key)
        Gets a resource defined using setResource(String, Resource) with the corresponding key.
        Parameters:
        key - the string identifier of the resource
        Returns:
        a resource, or null if there's no resource associated with the given key
        See Also:
        setResource(String, Resource)
      • setResource

        protected void setResource​(java.lang.String key,
                                   Resource resource)
        Registers a resource with this connector using the given key. This will make the URL for retrieving the resource available to the client-side connector using com.vaadin.terminal.gwt.client.ui.AbstractConnector#getResourceUrl(String) with the same key.
        Parameters:
        key - the string key to associate the resource with
        resource - the resource to set, or null to clear a previous association.
      • addListener

        @Deprecated
        protected com.vaadin.shared.Registration addListener​(java.lang.String eventIdentifier,
                                                             java.lang.Class<?> eventType,
                                                             java.lang.Object target,
                                                             java.lang.reflect.Method method)
        Deprecated.
        As of 8.12. Use strongly typed addListener(String, Class, SerializableEventListener, Method) method instead.
        Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        This method additionally informs the event-api to route events with the given eventIdentifier to the components handleEvent function call.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Parameters:
        eventIdentifier - the identifier of the event to listen for
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        target - the object instance who owns the activation method.
        method - the activation method.
        Returns:
        a registration object for removing the listener
        Since:
        8.0
      • addListener

        protected com.vaadin.shared.Registration addListener​(java.lang.String eventIdentifier,
                                                             java.lang.Class<?> eventType,
                                                             SerializableEventListener listener,
                                                             java.lang.reflect.Method method)
        Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        This method additionally informs the event-api to route events with the given eventIdentifier to the components handleEvent function call.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Parameters:
        eventIdentifier - the identifier of the event to listen for
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        listener - the listener instance who owns the activation method.
        method - the activation method.
        Returns:
        a registration object for removing the listener
        Since:
        8.12
      • hasListeners

        protected boolean hasListeners​(java.lang.Class<?> eventType)
        Checks if the given Component.Event type is listened for this component.
        Parameters:
        eventType - the event type to be checked
        Returns:
        true if a listener is registered for the given event type
      • removeListener

        @Deprecated
        protected void removeListener​(java.lang.String eventIdentifier,
                                      java.lang.Class<?> eventType,
                                      java.lang.Object target)
        Deprecated.
        use a Registration from addListener(Class, Object, Method) to remove a listener
        Removes all registered listeners matching the given parameters. Since this method receives the event type and the listener object as parameters, it will unregister all object's methods that are registered to listen to events of type eventType generated by this component.

        This method additionally informs the event-api to stop routing events with the given eventIdentifier to the components handleEvent function call.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Parameters:
        eventIdentifier - the identifier of the event to stop listening for
        eventType - the exact event type the object listens to.
        target - the target object that has registered to listen to events of type eventType with one or more methods.
        Since:
        6.2
      • addListener

        @Deprecated
        public com.vaadin.shared.Registration addListener​(java.lang.Class<?> eventType,
                                                          java.lang.Object target,
                                                          java.lang.reflect.Method method)
        Deprecated.
        As of 8.12. Use strongly typed addListener(Class, SerializableEventListener, Method) method instead.
        Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Specified by:
        addListener in interface MethodEventSource
        Parameters:
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        target - the object instance who owns the activation method.
        method - the activation method.
        Returns:
        a registration object for removing the listener
      • addListener

        public com.vaadin.shared.Registration addListener​(java.lang.Class<?> eventType,
                                                          SerializableEventListener listener,
                                                          java.lang.reflect.Method method)
        Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Specified by:
        addListener in interface MethodEventSource
        Parameters:
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        listener - the listener instance who owns the activation method.
        method - the activation method.
        Returns:
        a registration object for removing the listener
        Since:
        8.12
      • addListener

        @Deprecated
        public com.vaadin.shared.Registration addListener​(java.lang.Class<?> eventType,
                                                          java.lang.Object target,
                                                          java.lang.String methodName)
        Convenience method for registering a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        This version of addListener gets the name of the activation method as a parameter. The actual method is reflected from object, and unless exactly one match is found, java.lang.IllegalArgumentException is thrown.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Note: Using this method is discouraged because it cannot be checked during compilation. Use addListener(Class, Object, Method) or addListener(String, Class, Object, Method) instead.

        Specified by:
        addListener in interface MethodEventSource
        Parameters:
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        target - the object instance who owns the activation method.
        methodName - the name of the activation method.
        Returns:
        a registration object for removing the listener
        Since:
        8.0
      • addListener

        @Deprecated
        public com.vaadin.shared.Registration addListener​(java.lang.Class<?> eventType,
                                                          SerializableEventListener listener,
                                                          java.lang.String methodName)
        Deprecated.
        This method has only been added for ease of migration and should be avoided in new code. Use addListener(Class, SerializableEventListener, Method) or addListener(String, Class, SerializableEventListener, Method) instead.
        Convenience method for registering a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.

        This version of addListener gets the name of the activation method as a parameter. The actual method is reflected from object, and unless exactly one match is found, java.lang.IllegalArgumentException is thrown.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Note: Using this method is discouraged because it cannot be checked during compilation. Use addListener(Class, Object, Method) or addListener(String, Class, Object, Method) instead.

        Specified by:
        addListener in interface MethodEventSource
        Parameters:
        eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
        listener - the object instance who owns the activation method.
        methodName - the name of the activation method.
        Returns:
        a registration object for removing the listener
        Since:
        8.12
      • removeListener

        @Deprecated
        public void removeListener​(java.lang.Class<?> eventType,
                                   java.lang.Object target)
        Removes all registered listeners matching the given parameters. Since this method receives the event type and the listener object as parameters, it will unregister all object's methods that are registered to listen to events of type eventType generated by this component.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Specified by:
        removeListener in interface MethodEventSource
        Parameters:
        eventType - the exact event type the object listens to.
        target - the target object that has registered to listen to events of type eventType with one or more methods.
      • removeListener

        @Deprecated
        public void removeListener​(java.lang.Class<?> eventType,
                                   java.lang.Object target,
                                   java.lang.reflect.Method method)
        Deprecated.
        use a Registration from addListener(Class, Object, Method) to remove a listener
        Removes one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Specified by:
        removeListener in interface MethodEventSource
        Parameters:
        eventType - the exact event type the object listens to.
        target - target object that has registered to listen to events of type eventType with one or more methods.
        method - the method owned by target that's registered to listen to events of type eventType.
      • removeListener

        @Deprecated
        public void removeListener​(java.lang.Class<?> eventType,
                                   java.lang.Object target,
                                   java.lang.String methodName)
        Deprecated.
        As of 7.0. This method should be avoided. Use removeListener(Class, Object, Method) instead.

        Removes one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.

        This version of removeListener gets the name of the activation method as a parameter. The actual method is reflected from target, and unless exactly one match is found, java.lang.IllegalArgumentException is thrown.

        For more information on the inheritable event mechanism see the com.vaadin.event package documentation.

        Specified by:
        removeListener in interface MethodEventSource
        Parameters:
        eventType - the exact event type the object listens to.
        target - the target object that has registered to listen to events of type eventType with one or more methods.
        methodName - the name of the method owned by target that's registered to listen to events of type eventType.
      • getListeners

        public java.util.Collection<?> getListeners​(java.lang.Class<?> eventType)
        Returns all listeners that are registered for the given event type or one of its subclasses.
        Parameters:
        eventType - The type of event to return listeners for.
        Returns:
        A collection with all registered listeners. Empty if no listeners are found.
      • fireEvent

        protected void fireEvent​(java.util.EventObject event)
        Sends the event to all listeners.
        Parameters:
        event - the Event to be sent to all listeners.
      • getErrorHandler

        public ErrorHandler getErrorHandler()
        Description copied from interface: ClientConnector
        Gets the error handler for the connector. The error handler is dispatched whenever there is an error processing the data coming from the client to this connector.
        Specified by:
        getErrorHandler in interface ClientConnector
        Returns:
        The error handler or null if not set
      • setErrorHandler

        public void setErrorHandler​(ErrorHandler errorHandler)
        Description copied from interface: ClientConnector
        Sets the error handler for the connector. The error handler is dispatched whenever there is an error processing the data coming from the client for this connector.
        Specified by:
        setErrorHandler in interface ClientConnector
        Parameters:
        errorHandler - The error handler for this connector
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • isThis

        @Deprecated
        protected boolean isThis​(java.lang.Object that)
        Deprecated.
        only defined for framework hacks, do not use.
        For internal use only, may be changed or removed in future versions.

        This method must be protected, because otherwise it will not be redefined by the proxy to actually be called on the underlying instance.

        See #14639

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • updateDiffstate

        protected void updateDiffstate​(java.lang.String propertyName,
                                       elemental.json.JsonValue newValue)
        Sets the expected value of a state property so that changes can be properly sent to the client. This needs to be done in cases where a state change originates from the client, since otherwise the server-side would fail to recognize if the value is changed back to its previous value.
        Parameters:
        propertyName - the name of the shared state property to update
        newValue - the new diffstate reference value