Class UICommand
- java.lang.Object
-
- javax.faces.component.UIComponent
-
- javax.faces.component.UIComponentBase
-
- javax.faces.component.UICommand
-
- All Implemented Interfaces:
java.util.EventListener,ActionSource,ActionSource2,PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder
- Direct Known Subclasses:
HtmlCommandButton,HtmlCommandLink
public class UICommand extends UIComponentBase implements ActionSource2
UICommand is a
UIComponentthat 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 thisUICommand, or its correspondingRenderer, detects that this control has been activated, it will queue anActionEvent. Later on, thebroadcast()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
rendererTypeproperty must be set to "javax.faces.Button". This value can be changed by calling thesetRendererType()method.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCOMPONENT_FAMILYThe standard component family for this component.static java.lang.StringCOMPONENT_TYPEThe standard component type for this component.-
Fields inherited from class javax.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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddActionListener(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(javax.faces.event.FacesEvent)processing, pass theActionEventbeing broadcast to the method referenced byactionListener(if any), and to the defaultActionListenerregistered on theApplication.MethodBindinggetAction()Deprecated.This has been replaced bygetActionExpression().javax.el.MethodExpressiongetActionExpression()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.MethodBindinggetActionListener()Deprecated.UsegetActionListeners()instead.ActionListener[]getActionListeners()Return the set of registeredActionListeners for thisActionSourceinstance.java.lang.StringgetFamily()Return the identifier of the component family to which this component belongs.java.lang.ObjectgetValue()Returns thevalueproperty of theUICommand.booleanisImmediate()The immediate flag.voidqueueEvent(FacesEvent e)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(javax.el.MethodExpression).voidsetActionExpression(javax.el.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(javax.faces.event.ActionListener).voidsetImmediate(boolean immediate)Set the "immediate execution" flag for thisUIComponent.voidsetValue(java.lang.Object value)Sets thevalueproperty of theUICommand.-
Methods inherited from class javax.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, unsubscribeFromEvent
-
Methods inherited from class javax.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 Detail
-
COMPONENT_TYPE
public static final java.lang.String COMPONENT_TYPE
The standard component type for this component.
- See Also:
- Constant Field Values
-
COMPONENT_FAMILY
public static final java.lang.String COMPONENT_FAMILY
The standard component family for this component.
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UICommand
public UICommand()
Create a new
UICommandinstance with default property values.
-
-
Method Detail
-
getFamily
public java.lang.String 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.- Specified by:
getFamilyin classUIComponent
-
getAction
public MethodBinding 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(javax.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
-
setAction
public void setAction(MethodBinding action)
Deprecated.This has been replaced bysetActionExpression(javax.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(javax.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
public MethodBinding getActionListener()
Deprecated.UsegetActionListeners()instead.If
ActionSource.setActionListener(javax.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(javax.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
-
setActionListener
public void setActionListener(MethodBinding actionListener)
Deprecated.This has been replaced byaddActionListener(javax.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
-
isImmediate
public boolean isImmediate()
The immediate flag.
- Specified by:
isImmediatein interfaceActionSource
-
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
public java.lang.Object getValue()
Returns the
valueproperty of theUICommand. This is most often rendered as a label.
-
setValue
public void setValue(java.lang.Object value)
Sets the
valueproperty of theUICommand. This is most often rendered as a label.- Parameters:
value- the new value
-
getActionExpression
public javax.el.MethodExpression 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(javax.faces.el.MethodBinding). This makes it possible for the defaultActionListenerto continue to work properly with older components.- Specified by:
getActionExpressionin interfaceActionSource2
-
setActionExpression
public void setActionExpression(javax.el.MethodExpression actionExpression)
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
public void addActionListener(ActionListener listener)
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:
java.lang.NullPointerException- iflistenerisnull
-
getActionListeners
public ActionListener[] 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
-
removeActionListener
public void removeActionListener(ActionListener listener)
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:
java.lang.NullPointerException- iflistenerisnull
-
broadcast
public void broadcast(FacesEvent event) throws AbortProcessingException
In addition to to the default
UIComponent.broadcast(javax.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 JavaServer Faces implementation that no further processing on the current event should be performedjava.lang.IllegalArgumentException- if the implementation class of thisFacesEventis not supported by this componentjava.lang.NullPointerException- ifeventisnull
-
queueEvent
public void queueEvent(FacesEvent e)
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:
e-FacesEventto be queued
-
-