- All Implemented Interfaces:
ActionSource
,PartialStateHolder
,StateHolder
,TransientStateHolder
,ComponentSystemEventListener
,FacesListener
,SystemEventListenerHolder
,EventListener
- Direct Known Subclasses:
HtmlCommandButton
,HtmlCommandLink
,HtmlCommandScript
UICommand is a UIComponent
that represents a user interface component which, when activated
by the user, triggers an application specific "command" or "action". Such a component is typically rendered as a push
button, a menu item, or a hyperlink.
When the decode()
method of this UICommand
, or its corresponding Renderer
, detects that
this control has been activated, it will queue an ActionEvent
. Later on, the broadcast()
method
will ensure that this event is broadcast to all interested listeners.
Listeners will be invoked in the following order:
ActionListener
s, in the order in which they were registered.- The "actionListener"
MethodExpression
(which will cover the "actionListener" that was set as aMethodBinding
). - The default
ActionListener
, retrieved from theApplication
- and therefore, any attached "action"MethodExpression
.
By default, the rendererType
property must be set to "jakarta.faces.Button
". This value can
be changed by calling the setRendererType()
method.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The standard component family for this component.static final String
The standard component type for this component.Fields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addActionListener
(ActionListener listener) Add a newActionListener
to the set of listeners interested in being notified whenActionEvent
s occur.void
broadcast
(FacesEvent event) In addition to to the defaultUIComponent.broadcast(jakarta.faces.event.FacesEvent)
processing, pass theActionEvent
being broadcast to the method referenced byactionListener
(if any), and to the defaultActionListener
registered on theApplication
.Return theMethodExpression
pointing at the application action to be invoked, if thisUIComponent
is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediate
property.Return the set of registeredActionListener
s for thisActionSource
instance.Return the identifier of the component family to which this component belongs.getValue()
Returns thevalue
property of theUICommand
.boolean
The immediate flag.void
queueEvent
(FacesEvent event) InterceptqueueEvent
and take the following action.void
removeActionListener
(ActionListener listener) Remove an existingActionListener
(if any) from the set of listeners interested in being notified whenActionEvent
s occur.void
setActionExpression
(MethodExpression actionExpression) Set theMethodExpression
pointing at the appication action to be invoked, if thisUIComponent
is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediate
property.void
setImmediate
(boolean immediate) Set the "immediate execution" flag for thisUIComponent
.void
Sets thevalue
property of theUICommand
.Methods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, clearInitialState, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, subscribeToEvent, unsubscribeFromEvent
Methods inherited from class jakarta.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
-
Field Details
-
COMPONENT_TYPE
-
COMPONENT_FAMILY
The standard component family for this component.
- See Also:
-
-
Constructor Details
-
UICommand
public UICommand()Create a new
UICommand
instance with default property values.
-
-
Method Details
-
getFamily
Description copied from class:UIComponent
Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererType
property, may be used to select the appropriateRenderer
for this component instance. Note this method should NOT returnnull
- Specified by:
getFamily
in classUIComponent
- Returns:
- the component family (not null).
-
isImmediate
public boolean isImmediate()The immediate flag.
- Specified by:
isImmediate
in interfaceActionSource
- Returns:
true
if immediate,false
otherwise.
-
setImmediate
public void setImmediate(boolean immediate) Description copied from interface:ActionSource
Set the "immediate execution" flag for this
UIComponent
.- Specified by:
setImmediate
in interfaceActionSource
- Parameters:
immediate
- The new immediate execution flag
-
getValue
Returns the
value
property of theUICommand
. This is most often rendered as a label.- Returns:
- The object representing the value of this component.
-
setValue
Sets the
value
property of theUICommand
. This is most often rendered as a label.- Parameters:
value
- the new value
-
getActionExpression
Description copied from interface:ActionSource
Return the
MethodExpression
pointing at the application action to be invoked, if thisUIComponent
is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediate
property.The default implementation throws
UnsupportedOperationException
and is provided for the sole purpose of not breaking existing applications that extendActionSource
. Historically this method was declared inActionSource2
for precisely this reason but default methods in interfaces weren't supported.- Specified by:
getActionExpression
in interfaceActionSource
- Returns:
- the action expression.
-
setActionExpression
Description copied from interface:ActionSource
Set the
MethodExpression
pointing at the appication action to be invoked, if thisUIComponent
is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediate
property.Any method referenced by such an expression must be public, with a return type of
String
, and accept no parameters.The default implementation throws
UnsupportedOperationException
and is provided for the sole purpose of not breaking existing applications that extendActionSource
. Historically this method was declared inActionSource2
for precisely this reason but default methods in interfaces weren't supported.- Specified by:
setActionExpression
in interfaceActionSource
- Parameters:
actionExpression
- The new method expression
-
addActionListener
Description copied from interface:ActionSource
Add a new
ActionListener
to the set of listeners interested in being notified whenActionEvent
s occur.- Specified by:
addActionListener
in interfaceActionSource
- Parameters:
listener
- TheActionListener
to be added- Throws:
NullPointerException
- iflistener
isnull
-
getActionListeners
Description copied from interface:ActionSource
Return the set of registered
ActionListener
s for thisActionSource
instance. If there are no registered listeners, a zero-length array is returned.- Specified by:
getActionListeners
in interfaceActionSource
- Returns:
- the action listeners, or a zero-length array.
-
removeActionListener
Description copied from interface:ActionSource
Remove an existing
ActionListener
(if any) from the set of listeners interested in being notified whenActionEvent
s occur.- Specified by:
removeActionListener
in interfaceActionSource
- Parameters:
listener
- TheActionListener
to be removed- Throws:
NullPointerException
- iflistener
isnull
-
broadcast
In addition to to the default
UIComponent.broadcast(jakarta.faces.event.FacesEvent)
processing, pass theActionEvent
being broadcast to the method referenced byactionListener
(if any), and to the defaultActionListener
registered on theApplication
.- Overrides:
broadcast
in classUIComponentBase
- Parameters:
event
-FacesEvent
to be broadcast- Throws:
AbortProcessingException
- Signal the Jakarta Faces implementation that no further processing on the current event should be performedIllegalArgumentException
- if the implementation class of thisFacesEvent
is not supported by this componentNullPointerException
- ifevent
isnull
-
queueEvent
Intercept
queueEvent
and take the following action. If the event is an
, obtain theActionEvent
UIComponent
instance from the event. If the component is an
obtain the value of its "immediate" property. If it is true, mark the phaseId for the event to beActionSource
PhaseId.APPLY_REQUEST_VALUES
otherwise, mark the phaseId to bePhaseId.INVOKE_APPLICATION
. The event must be passed on tosuper.queueEvent()
before returning from this method.- Overrides:
queueEvent
in classUIComponentBase
- Parameters:
event
-FacesEvent
to be queued
-