Class UIWebsocket

    • Field Detail

      • COMPONENT_TYPE

        public static final java.lang.String COMPONENT_TYPE

        The standard component type for this component.

        See Also:
        Constant Field Values
      • COMPONENT_FAMILY

        public static final java.lang.String COMPONENT_FAMILY

        The standard component family for this component.

        See Also:
        Constant Field Values
    • Constructor Detail

      • UIWebsocket

        public UIWebsocket​()

        Create a new UIWebsocket instance with default property values.

        Throws:
        java.lang.IllegalStateException - When Websocket endpoint is not enabled.
    • Method Detail

      • setValueExpression

        public void setValueExpression​(java.lang.String name,
                                       ValueExpression binding)

        Set the ValueExpression used to calculate the value for the specified attribute or property name, if any. If a ValueExpression is set for the channel or scope property, regardless of the value, throw an illegal argument exception. If a ValueExpression is set for the user property, and the non-null value is not an instance of Serializable, throw an illegal argument exception.

        Overrides:
        setValueExpression in class UIComponent
        Parameters:
        name - Name of the attribute or property for which to set a ValueExpression
        binding - The ValueExpression to set, or null to remove any currently set ValueExpression
        Throws:
        java.lang.IllegalArgumentException - If name is one of id, parent, channel or scope, or it name is user and the non-null value is not an instance of Serializable.
        java.lang.NullPointerException - If name is null.
      • getEventNames

        public java.util.Collection<java.lang.String> getEventNames​()

        Returns a non-null, empty, unmodifiable Collection which returns true on any Collection#contains() invocation, indicating that all client behavior event names are acceptable.

        Specified by:
        getEventNames in interface ClientBehaviorHolder
        Overrides:
        getEventNames in class UIComponentBase
        Returns:
        the collection of event names.
      • getChannel

        public java.lang.String getChannel​()
        Returns the name of the websocket channel.
        Returns:
        The name of the websocket channel.
      • setChannel

        public void setChannel​(java.lang.String channel)
        Sets the name of the websocket channel. It may not be an EL expression and it may only contain alphanumeric characters, hyphens, underscores and periods. All open websockets on the same channel will receive the same push message from the server.
        Parameters:
        channel - The name of the websocket channel.
        Throws:
        java.lang.IllegalArgumentException - When the value does not represent a valid channel name.
      • getScope

        public java.lang.String getScope​()
        Returns the scope of the websocket channel.
        Returns:
        The scope of the websocket channel.
      • setScope

        public void setScope​(java.lang.String scope)
        Sets the scope of the websocket channel. It may not be an EL expression and allowed values are application, session and view, case insensitive. When the value is application, then all channels with the same name throughout the application will receive the same push message. When the value is session, then only the channels with the same name in the current user session will receive the same push message. When the value is view, then only the channel in the current view will receive the push message. The default scope is application. When the user attribute is specified, then the default scope is session.
        Parameters:
        scope - The scope of the websocket channel.
      • getUser

        public java.io.Serializable getUser​()
        Returns the user identifier of the websocket channel.
        Returns:
        The user identifier of the websocket channel.
      • setUser

        public void setUser​(java.io.Serializable user)
        Sets the user identifier of the websocket channel, so that user-targeted push messages can be sent. All open websockets on the same channel and user will receive the same push message from the server. It must implement Serializable and preferably have low memory footprint. Suggestion: use #{request.remoteUser} or #{someLoggedInUser.id}.
        Parameters:
        user - The user identifier of the websocket channel.
      • getOnopen

        public java.lang.String getOnopen​()
        Returns the JavaScript event handler function that is invoked when the websocket is opened.
        Returns:
        The JavaScript event handler function that is invoked when the websocket is opened.
      • setOnopen

        public void setOnopen​(java.lang.String onopen)
        Sets the JavaScript event handler function that is invoked when the websocket is opened. The function will be invoked with one argument: the channel name.
        Parameters:
        onopen - The JavaScript event handler function that is invoked when the websocket is opened.
      • getOnmessage

        public java.lang.String getOnmessage​()
        Returns the JavaScript event handler function that is invoked when a push message is received from the server.
        Returns:
        The JavaScript event handler function that is invoked when a push message is received from the server.
      • setOnmessage

        public void setOnmessage​(java.lang.String onmessage)
        Sets the JavaScript event handler function that is invoked when a push message is received from the server. The function will be invoked with three arguments: the push message, the channel name and the raw MessageEvent itself.
        Parameters:
        onmessage - The JavaScript event handler function that is invoked when a push message is received from the server.
      • getOnclose

        public java.lang.String getOnclose​()
        Returns the JavaScript event handler function that is invoked when the websocket is closed.
        Returns:
        The JavaScript event handler function that is invoked when the websocket is closed.
      • setOnclose

        public void setOnclose​(java.lang.String onclose)
        Sets the JavaScript event handler function that is invoked when the websocket is closed. The function will be invoked with three arguments: the close reason code, the channel name and the raw CloseEvent itself. Note that this will also be invoked on errors and that you can inspect the close reason code if an error occurred and which one (i.e. when the code is not 1000). See also RFC 6455 section 7.4.1 and CloseReason.CloseCodes API for an elaborate list of all close codes.
        Parameters:
        onclose - The JavaScript event handler function that is invoked when the websocket is closed.
      • isConnected

        public boolean isConnected​()
        Returns whether to (auto)connect the websocket or not.
        Returns:
        Whether to (auto)connect the websocket or not.
      • setConnected

        public void setConnected​(boolean connected)
        Sets whether to (auto)connect the websocket or not. Defaults to true. It's interpreted as a JavaScript instruction whether to open or close the websocket push connection. Note that this attribute is re-evaluated on every ajax request. You can also explicitly set it to false and then manually control in JavaScript by OmniFaces.Push.open("channelName") and OmniFaces.Push.close("channelName").
        Parameters:
        connected - Whether to (auto)connect the websocket or not.