Top Description Inners Fields Constructors Methods
javax.faces.component

public Class UIWebsocket

extends UIComponentBase
implements ClientBehaviorHolder
Class Inheritance
All Implemented Interfaces
javax.faces.component.behavior.ClientBehaviorHolder
Static Imports
java.util.Collections.unmodifiableList, javax.faces.push.PushContext.ENABLE_WEBSOCKET_ENDPOINT_PARAM_NAME

The <f:websocket> tag opens an one-way (server to client) websocket based push connection in client side which can be reached from server side via PushContext interface injected in any CDI/container managed artifact via @Push annotation.

By default, the rendererType property must be set to "javax.faces.Websocket". This value can be changed by calling the setRendererType() method.

For detailed usage instructions, see @Push javadoc.

Since
2.3
See Also
Push

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
UIWebsocket.PropertyKeys

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final String
COMPONENT_FAMILY

The standard component family for this component.

public static final String
COMPONENT_TYPE

The standard component type for this component.

private static final Collection<String>
private static final String
private static final String
private static final String
private static final Pattern

Constructor Summary

AccessConstructor and Description
public
UIWebsocket()

Create a new UIWebsocket instance with default property values.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The name of the websocket channel.
getChannel
()

Returns the name of the websocket channel.

public Collection<String>
getEventNames()

Overrides javax.faces.component.UIComponentBase.getEventNames.

Implements javax.faces.component.behavior.ClientBehaviorHolder.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.

public String
public String

Returns:

The JavaScript event handler function that is invoked when the websocket is closed.
getOnclose
()

Returns the JavaScript event handler function that is invoked when the websocket is closed.

public String

Returns:

The JavaScript event handler function that is invoked when a push message is received from the server.
getOnmessage
()

Returns the JavaScript event handler function that is invoked when a push message is received from the server.

public String

Returns:

The JavaScript event handler function that is invoked when the websocket is opened.
getOnopen
()

Returns the JavaScript event handler function that is invoked when the websocket is opened.

public String

Returns:

The scope of the websocket channel.
getScope
()

Returns the scope of the websocket channel.

public Serializable

Returns:

The user identifier of the websocket channel.
getUser
()

Returns the user identifier of the websocket channel.

public boolean

Returns:

Whether to (auto)connect the websocket or not.
isConnected
()

Returns whether to (auto)connect the websocket or not.

public void
setChannel(String
The name of the websocket channel.
channel
)

Sets the name of the websocket channel.

public void
setConnected(boolean
Whether to (auto)connect the websocket or not.
connected
)

Sets whether to (auto)connect the websocket or not.

public void
setOnclose(String
The JavaScript event handler function that is invoked when the websocket is closed.
onclose
)

Sets the JavaScript event handler function that is invoked when the websocket is closed.

public void
setOnmessage(String
The JavaScript event handler function that is invoked when a push message is received from the server.
onmessage
)

Sets the JavaScript event handler function that is invoked when a push message is received from the server.

public void
setOnopen(String
The JavaScript event handler function that is invoked when the websocket is opened.
onopen
)

Sets the JavaScript event handler function that is invoked when the websocket is opened.

public void
setScope(String
The scope of the websocket channel.
scope
)

Sets the scope of the websocket channel.

public void
setUser(Serializable
The user identifier of the websocket channel.
user
)

Sets the user identifier of the websocket channel, so that user-targeted push messages can be sent.

public void
setValueExpression(String
Name of the attribute or property for which to set a ValueExpression
name
,
ValueExpression
The ValueExpression to set, or null to remove any currently set ValueExpression
binding
)

Overrides javax.faces.component.UIComponent.setValueExpression.

Set the ValueExpression used to calculate the value for the specified attribute or property name, if any.

Inherited from javax.faces.component.UIComponentBase:
addClientBehavioraddFacesListenerbroadcastclearInitialStatedecodeencodeBeginencodeChildrenencodeEndfindComponentgetAttributesgetChildCountgetChildrengetClientBehaviorsgetClientIdgetDefaultEventNamegetDescriptorMapgetFacesContextgetFacesListenersgetFacetgetFacetCountgetFacetsgetFacetsAndChildrengetIdgetListenersForEventClassgetParentgetPassThroughAttributesgetRenderergetRendererTypegetRendersChildrengetValueBindinginvokeOnComponentisRenderedisTransientmarkInitialStateprocessDecodesprocessRestoreStateprocessSaveStateprocessUpdatesprocessValidatorsqueueEventremoveFacesListenerrestoreAttachedStaterestoreStatesaveAttachedStatesaveStatesetIdsetParentsetRenderedsetRendererTypesetTransientsetValueBindingsubscribeToEventunsubscribeFromEvent

Field Detail

COMPONENT_FAMILYback to summary
public static final String COMPONENT_FAMILY

The standard component family for this component.

COMPONENT_TYPEback to summary
public static final String COMPONENT_TYPE

The standard component type for this component.

CONTAINS_EVERYTHINGback to summary
private static final Collection<String> CONTAINS_EVERYTHING
ERROR_ENDPOINT_NOT_ENABLEDback to summary
private static final String ERROR_ENDPOINT_NOT_ENABLED
ERROR_INVALID_CHANNELback to summary
private static final String ERROR_INVALID_CHANNEL
ERROR_INVALID_USERback to summary
private static final String ERROR_INVALID_USER
PATTERN_CHANNEL_NAMEback to summary
private static final Pattern PATTERN_CHANNEL_NAME

Constructor Detail

UIWebsocketback to summary
public UIWebsocket()

Create a new UIWebsocket instance with default property values.

Exceptions
IllegalStateException:
When Websocket endpoint is not enabled.

Method Detail

getChannelback to summary
public String getChannel()

Returns the name of the websocket channel.

Returns:String

The name of the websocket channel.

getEventNamesback to summary
public Collection<String> getEventNames()

Overrides javax.faces.component.UIComponentBase.getEventNames.

Implements javax.faces.component.behavior.ClientBehaviorHolder.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.

Returns:Collection<String>

Doc from javax.faces.component.behavior.ClientBehaviorHolder.getEventNames.

an unmodifiable collection of event names.

Annotations
@Override
getFamilyback to summary
public String getFamily()

Implements abstract javax.faces.component.UIComponent.getFamily.

Returns UIWebsocket#COMPONENT_FAMILY.

Returns:String

Doc from javax.faces.component.UIComponent.getFamily.

the component family (not null).

Annotations
@Override
getOncloseback to summary
public String getOnclose()

Returns the JavaScript event handler function that is invoked when the websocket is closed.

Returns:String

The JavaScript event handler function that is invoked when the websocket is closed.

getOnmessageback to summary
public String getOnmessage()

Returns the JavaScript event handler function that is invoked when a push message is received from the server.

Returns:String

The JavaScript event handler function that is invoked when a push message is received from the server.

getOnopenback to summary
public String getOnopen()

Returns the JavaScript event handler function that is invoked when the websocket is opened.

Returns:String

The JavaScript event handler function that is invoked when the websocket is opened.

getScopeback to summary
public String getScope()

Returns the scope of the websocket channel.

Returns:String

The scope of the websocket channel.

getUserback to summary
public Serializable getUser()

Returns the user identifier of the websocket channel.

Returns:Serializable

The user identifier of the websocket channel.

isConnectedback to summary
public boolean isConnected()

Returns whether to (auto)connect the websocket or not.

Returns:boolean

Whether to (auto)connect the websocket or not.

setChannelback to summary
public void setChannel(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:String

The name of the websocket channel.

Exceptions
IllegalArgumentException:
When the value does not represent a valid channel name.
setConnectedback to summary
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:boolean

Whether to (auto)connect the websocket or not.

setOncloseback to summary
public void setOnclose(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 CloseCodes API for an elaborate list of all close codes.

Parameters
onclose:String

The JavaScript event handler function that is invoked when the websocket is closed.

setOnmessageback to summary
public void setOnmessage(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:String

The JavaScript event handler function that is invoked when a push message is received from the server.

setOnopenback to summary
public void setOnopen(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:String

The JavaScript event handler function that is invoked when the websocket is opened.

setScopeback to summary
public void setScope(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:String

The scope of the websocket channel.

setUserback to summary
public void setUser(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:Serializable

The user identifier of the websocket channel.

setValueExpressionback to summary
public void setValueExpression(String name, ValueExpression binding)

Overrides javax.faces.component.UIComponent.setValueExpression.

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.

Parameters
name:String

Doc from javax.faces.component.UIComponent.setValueExpression.

Name of the attribute or property for which to set a ValueExpression

binding:ValueExpression

Doc from javax.faces.component.UIComponent.setValueExpression.

The ValueExpression to set, or null to remove any currently set ValueExpression

Annotations
@Override
Exceptions
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.
NullPointerException:
If name is null.
javax.faces.component back to summary

pack-priv final Enum UIWebsocket.PropertyKeys

extends Enum<UIWebsocket.PropertyKeys>
Class Inheritance

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys
public static final UIWebsocket.PropertyKeys

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UIWebsocket.PropertyKeys
public static UIWebsocket.PropertyKeys[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

channelback to summary
public static final UIWebsocket.PropertyKeys channel
connectedback to summary
public static final UIWebsocket.PropertyKeys connected
oncloseback to summary
public static final UIWebsocket.PropertyKeys onclose
onmessageback to summary
public static final UIWebsocket.PropertyKeys onmessage
onopenback to summary
public static final UIWebsocket.PropertyKeys onopen
scopeback to summary
public static final UIWebsocket.PropertyKeys scope
userback to summary
public static final UIWebsocket.PropertyKeys user

Constructor Detail

PropertyKeysback to summary
private PropertyKeys()

Method Detail

valueOfback to summary
public static UIWebsocket.PropertyKeys valueOf(String name)
valuesback to summary
public static UIWebsocket.PropertyKeys[] values()