Class UICommand
- 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:
ActionListeners, 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
FieldsModifier and TypeFieldDescriptionstatic final StringThe standard component family for this component.static final StringThe 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionListener(ActionListener listener) Add a newActionListenerto the set of listeners interested in being notified whenActionEvents occur.voidbroadcast(FacesEvent event) In addition to to the defaultUIComponent.broadcast(jakarta.faces.event.FacesEvent)processing, pass theActionEventbeing broadcast to the method referenced byactionListener(if any), and to the defaultActionListenerregistered on theApplication.Return theMethodExpressionpointing at the application action to be invoked, if thisUIComponentis activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediateproperty.Return the set of registeredActionListeners for thisActionSourceinstance.Return the identifier of the component family to which this component belongs.getValue()Returns thevalueproperty of theUICommand.booleanThe immediate flag.voidqueueEvent(FacesEvent event) InterceptqueueEventand take the following action.voidremoveActionListener(ActionListener listener) Remove an existingActionListener(if any) from the set of listeners interested in being notified whenActionEvents occur.voidsetActionExpression(MethodExpression actionExpression) Set theMethodExpressionpointing at the appication action to be invoked, if thisUIComponentis activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediateproperty.voidsetImmediate(boolean immediate) Set the "immediate execution" flag for thisUIComponent.voidSets thevalueproperty 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, unsubscribeFromEventMethods 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
The standard component type for this component.
- See Also:
-
COMPONENT_FAMILY
The standard component family for this component.
- See Also:
-
-
Constructor Details
-
UICommand
public UICommand()Create a new
UICommandinstance with default property values.
-
-
Method Details
-
getFamily
Description copied from class:UIComponentReturn the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererTypeproperty, may be used to select the appropriateRendererfor this component instance. Note this method should NOT returnnull- Specified by:
getFamilyin classUIComponent- Returns:
- the component family (not null).
-
isImmediate
public boolean isImmediate()The immediate flag.
- Specified by:
isImmediatein interfaceActionSource- Returns:
trueif immediate,falseotherwise.
-
setImmediate
public void setImmediate(boolean immediate) Description copied from interface:ActionSourceSet the "immediate execution" flag for this
UIComponent.- Specified by:
setImmediatein interfaceActionSource- Parameters:
immediate- The new immediate execution flag
-
getValue
Returns the
valueproperty of theUICommand. This is most often rendered as a label.- Returns:
- The object representing the value of this component.
-
setValue
Sets the
valueproperty of theUICommand. This is most often rendered as a label.- Parameters:
value- the new value
-
getActionExpression
Description copied from interface:ActionSourceReturn the
MethodExpressionpointing at the application action to be invoked, if thisUIComponentis activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediateproperty.The default implementation throws
UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extendActionSource. Historically this method was declared inActionSource2for precisely this reason but default methods in interfaces weren't supported.- Specified by:
getActionExpressionin interfaceActionSource- Returns:
- the action expression.
-
setActionExpression
Description copied from interface:ActionSourceSet the
MethodExpressionpointing at the appication action to be invoked, if thisUIComponentis activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of theimmediateproperty.Any method referenced by such an expression must be public, with a return type of
String, and accept no parameters.The default implementation throws
UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extendActionSource. Historically this method was declared inActionSource2for precisely this reason but default methods in interfaces weren't supported.- Specified by:
setActionExpressionin interfaceActionSource- Parameters:
actionExpression- The new method expression
-
addActionListener
Description copied from interface:ActionSourceAdd a new
ActionListenerto the set of listeners interested in being notified whenActionEvents occur.- Specified by:
addActionListenerin interfaceActionSource- Parameters:
listener- TheActionListenerto be added- Throws:
NullPointerException- iflistenerisnull
-
getActionListeners
Description copied from interface:ActionSourceReturn the set of registered
ActionListeners for thisActionSourceinstance. If there are no registered listeners, a zero-length array is returned.- Specified by:
getActionListenersin interfaceActionSource- Returns:
- the action listeners, or a zero-length array.
-
removeActionListener
Description copied from interface:ActionSourceRemove an existing
ActionListener(if any) from the set of listeners interested in being notified whenActionEvents occur.- Specified by:
removeActionListenerin interfaceActionSource- Parameters:
listener- TheActionListenerto be removed- Throws:
NullPointerException- iflistenerisnull
-
broadcast
In addition to to the default
UIComponent.broadcast(jakarta.faces.event.FacesEvent)processing, pass theActionEventbeing broadcast to the method referenced byactionListener(if any), and to the defaultActionListenerregistered on theApplication.- Overrides:
broadcastin classUIComponentBase- Parameters:
event-FacesEventto 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 thisFacesEventis not supported by this componentNullPointerException- ifeventisnull
-
queueEvent
Intercept
queueEventand take the following action. If the event is an, obtain theActionEventUIComponentinstance from the event. If the component is anobtain the value of its "immediate" property. If it is true, mark the phaseId for the event to beActionSourcePhaseId.APPLY_REQUEST_VALUESotherwise, mark the phaseId to bePhaseId.INVOKE_APPLICATION. The event must be passed on tosuper.queueEvent()before returning from this method.- Overrides:
queueEventin classUIComponentBase- Parameters:
event-FacesEventto be queued
-