Class UICommand
- All Implemented Interfaces:
ActionSource,ActionSource2,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, 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 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.Deprecated.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.Deprecated.UsegetActionListeners()instead.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.voidsetAction(MethodBinding action) Deprecated.This has been replaced bysetActionExpression(jakarta.el.MethodExpression).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.voidsetActionListener(MethodBinding actionListener) Deprecated.This has been replaced byaddActionListener(jakarta.faces.event.ActionListener).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, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, 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:ActionSource2Return 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.Note that it's possible that the returned
MethodExpressionis just a wrapper around aMethodBindinginstance whith was set by a call toActionSource.setAction(jakarta.faces.el.MethodBinding). This makes it possible for the defaultActionListenerto continue to work properly with older components.- Specified by:
getActionExpressionin interfaceActionSource2- Returns:
- the action expression.
-
setActionExpression
Description copied from interface:ActionSource2Set 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.- Specified by:
setActionExpressionin interfaceActionSource2- 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 Server 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
-
getAction
Deprecated.This has been replaced bygetActionExpression().If the implementing class also implements
ActionSource2, the implementation of this method must call through toActionSource2.getActionExpression()and examine the result. If the result came from a previous call toActionSource.setAction(jakarta.faces.el.MethodBinding), extract theMethodBindingfrom it and return it. Otherwise, wrap the returnedMethodExpressionin aMethodBindingimplementation, and return it.If the implementing class does not implement
ActionSource2, return theMethodBindingpointing 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.- Specified by:
getActionin interfaceActionSource- Returns:
- the action.
-
setAction
Deprecated.This has been replaced bysetActionExpression(jakarta.el.MethodExpression).If the implementing class also implements
ActionSource2, the implementation of this method must wrap the argumentactionin a class that implementsMethodExpressionand call through toActionSource2.setActionExpression(jakarta.el.MethodExpression), passing the wrappedaction.If the implementing class does not implement
ActionSource2, set theMethodBindingpointing 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.- Specified by:
setActionin interfaceActionSource- Parameters:
action- The new MethodBinding expression
-
getActionListener
Deprecated.UsegetActionListeners()instead.If
ActionSource.setActionListener(jakarta.faces.el.MethodBinding)was not previously called for this instance, this method must returnnull. If it was called, this method must return the exactMethodBindinginstance that was passed toActionSource.setActionListener(jakarta.faces.el.MethodBinding).The method to be invoked, if this
UIComponentis activated by the user, will be called during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending upon the value of theimmediateproperty.- Specified by:
getActionListenerin interfaceActionSource- Returns:
- the action listener.
-
setActionListener
Deprecated.This has been replaced byaddActionListener(jakarta.faces.event.ActionListener).Wrap the argument
actionListenerin an implementation ofActionListenerand store it in the internal data structure that backs theActionSource.getActionListeners()method, taking care to over-write any instance that was stored by a previous call tosetActionListener.Any method referenced by such an expression must be public, with a return type of
void, and accept a single parameter of typeActionEvent.- Specified by:
setActionListenerin interfaceActionSource- Parameters:
actionListener- The new method binding expression
-
getActionExpression().