public class UIWebsocket extends UIComponentBase implements ClientBehaviorHolder
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 "jakarta.faces.Websocket". This value
can be changed by calling the setRendererType() method.
For detailed usage instructions, see @Push javadoc.
Push| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COMPONENT_FAMILY
The standard component family for this component.
|
static java.lang.String |
COMPONENT_TYPE
The standard component type for this component.
|
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY| Constructor and Description |
|---|
UIWebsocket()
Create a new
UIWebsocket instance with default property values. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getChannel()
Returns the name of the websocket channel.
|
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. |
java.lang.String |
getFamily()
Returns
COMPONENT_FAMILY. |
java.lang.String |
getOnclose()
Returns the JavaScript event handler function that is invoked when the websocket is closed.
|
java.lang.String |
getOnmessage()
Returns the JavaScript event handler function that is invoked when a push message is received from the server.
|
java.lang.String |
getOnopen()
Returns the JavaScript event handler function that is invoked when the websocket is opened.
|
java.lang.String |
getScope()
Returns the scope of the websocket channel.
|
java.io.Serializable |
getUser()
Returns the user identifier of the websocket channel.
|
boolean |
isConnected()
Returns whether to (auto)connect the websocket or not.
|
void |
setChannel(java.lang.String channel)
Sets the name of the websocket channel.
|
void |
setConnected(boolean connected)
Sets whether to (auto)connect the websocket or not.
|
void |
setOnclose(java.lang.String onclose)
Sets the JavaScript event handler function that is invoked when the websocket is closed.
|
void |
setOnmessage(java.lang.String onmessage)
Sets the JavaScript event handler function that is invoked when a push message is received from the server.
|
void |
setOnopen(java.lang.String onopen)
Sets the JavaScript event handler function that is invoked when the websocket is opened.
|
void |
setScope(java.lang.String scope)
Sets the scope of the websocket channel.
|
void |
setUser(java.io.Serializable user)
Sets the user identifier of the websocket channel, so that user-targeted push messages can be sent.
|
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. |
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEventencodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, visitTreeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddClientBehavior, getClientBehaviors, getDefaultEventNamepublic static final java.lang.String COMPONENT_TYPE
The standard component type for this component.
public static final java.lang.String COMPONENT_FAMILY
The standard component family for this component.
public UIWebsocket()
Create a new UIWebsocket instance with default property values.
java.lang.IllegalStateException - When Websocket endpoint is not enabled.public java.lang.String getFamily()
Returns COMPONENT_FAMILY.
getFamily in class UIComponentpublic 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.
setValueExpression in class UIComponentname - Name of the attribute or property for which to set a ValueExpressionbinding - The ValueExpression to set, or null to remove any currently set
ValueExpressionjava.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.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.
getEventNames in interface ClientBehaviorHoldergetEventNames in class UIComponentBasepublic java.lang.String getChannel()
public void setChannel(java.lang.String channel)
channel - The name of the websocket channel.java.lang.IllegalArgumentException - When the value does not represent a valid channel name.public java.lang.String getScope()
public void setScope(java.lang.String scope)
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.scope - The scope of the websocket channel.public java.io.Serializable getUser()
public void setUser(java.io.Serializable user)
Serializable and preferably have low memory footprint. Suggestion: use
#{request.remoteUser} or #{someLoggedInUser.id}.user - The user identifier of the websocket channel.public java.lang.String getOnopen()
public void setOnopen(java.lang.String onopen)
onopen - The JavaScript event handler function that is invoked when the websocket is opened.public java.lang.String getOnmessage()
public void setOnmessage(java.lang.String onmessage)
onmessage - The JavaScript event handler function that is invoked when a push message is received from the
server.public java.lang.String getOnclose()
public void setOnclose(java.lang.String onclose)
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.onclose - The JavaScript event handler function that is invoked when the websocket is closed.public boolean isConnected()
public void setConnected(boolean connected)
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").connected - Whether to (auto)connect the websocket or not.