Top Description Inners Fields Constructors Methods
jakarta.faces.component

public Class UIViewAction

extends UIComponentBase
implements ActionSource
Class Inheritance
All Implemented Interfaces
jakarta.faces.component.ActionSource
Imports
java.util.Map, jakarta.el.MethodExpression, jakarta.faces.FacesException, jakarta.faces.application.NavigationHandler, jakarta.faces.context.FacesContext, .FacesContextWrapper, jakarta.faces.event.AbortProcessingException, .ActionEvent, .ActionListener, .FacesEvent, .PhaseId, .PreRenderViewEvent, jakarta.faces.view.ViewMetadata

UIViewAction represents a method invocation that occurs during the request processing lifecycle, usually in response to an initial request, as opposed to a postback.

The jakarta.faces.view.ViewDeclarationLanguage implementation must cause an instance of this component to be placed in the view for each occurrence of an <f:viewAction /> element placed inside of an <f:metadata /> element. The user must place <f:metadata /> as a direct child of the UIViewRoot.

Because this class implements ActionSource, any actions that one would normally take on a component that implements ActionSource, such as UICommand, are valid for instances of this class. Instances of this class participate in the regular Jakarta Faces lifecycle, including on Ajax requests.

The purpose of this component is to provide a light-weight front-controller solution for executing code upon the loading of a Jakarta Faces view to support the integration of system services, content retrieval, view management, and navigation. This functionality is especially useful for non-faces (initial) requests.

The most common use case for this component is to take actions necessary for a particular view, often with the help of one or more UIViewParameters.

The NavigationHandler is consulted after the action is invoked to carry out the navigation case that matches the action signature and outcome. If a navigation case is matched that causes the new viewId to be different from the current viewId, the runtime must force a redirect to that matched navigation case with different viewId, regardless of whether or not the matched navigation case with different viewId called for a redirect. If the navigation will result in a flow transition, the appropriate metadata must be included in the query string for the redirect. See section 7.4.2 "Default NavigationHandler Algorithm" of the Jakarta Faces Specification Document, for the specification of how to handle <redirect /> cases.

It's important to note that the full component tree is not built before the UIViewAction components are processed on an non-faces (initial) request. Rather, the component tree only contains the ViewMetadata, an important part of the optimization of this component and what sets it apart from a PreRenderViewEvent listener.

Since
2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
UIViewAction.InstrumentedFacesContext

A FacesContext delegator that gives us the necessary controls over the FacesContext to allow the execution of the lifecycle to accomodate the UIViewAction sequence.

pack-priv static enum
UIViewAction.PropertyKeys

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final String
COMPONENT_FAMILY

The standard component family for this component.

public static final String
COMPONENT_TYPE

The standard component type for this component.

private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
UIViewAction()

Create a new UIViewAction instance with default property values.

Method Summary

Modifier and TypeMethod and Description
public void
addActionListener(final ActionListener
The ActionListener to be added
listener
)

Implements jakarta.faces.component.ActionSource.addActionListener.

Add a new ActionListener to the set of listeners interested in being notified when ActionEvents occur.

public void
broadcast(final FacesEvent
FacesEvent to be broadcast
event
)

Overrides jakarta.faces.component.UIComponentBase.broadcast.

Enable the method invocation specified by this component instance to return a value that performs navigation, similar in spirit to UICommand#broadcast.

public void
decode(final FacesContext
FacesContext for the request we are processing
context
)

Overrides jakarta.faces.component.UIComponentBase.decode.

Override behavior from the superclass to queue an ActionEvent that may result in the invocation of the action or any actionListeners that may be associated with this instance.

private boolean
public MethodExpression
getActionExpression()

Overrides default jakarta.faces.component.ActionSource.getActionExpression.

Return the MethodExpression pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property.

public ActionListener[]
getActionListeners()

Implements jakarta.faces.component.ActionSource.getActionListeners.

Return the set of registered ActionListeners for this ActionSource instance.

public String
getFamily()

Implements abstract jakarta.faces.component.UIComponent.getFamily.

Return the identifier of the component family to which this component belongs.

public String

Returns:

the phase (as string).
getPhase
()

Returns the name of the lifecycle phase in which the action is to be queued.

private PhaseId
private UIViewRoot
private void
public boolean
isImmediate()

Implements jakarta.faces.component.ActionSource.isImmediate.

If the value of the component's immediate attribute is true, the action will be invoked during the Apply Request Values Jakarta Faces lifecycle phase.

public boolean

Returns:

true if operating upon postback, false otherwise.
isOnPostback
()

If true this component will operate on postback.

public static boolean

Returns:

true is currently processing broadcast, false otherwise.
isProcessingBroadcast
(FacesContext
FacesContext for the current request
context
)

Returns true if the current request processing lifecycle is in the midst of processing the broadcast of an event queued during a call to decode.

public boolean

Returns:

true if it should take the actions, false otherwise.
isRendered
()

Overrides jakarta.faces.component.UIComponentBase.isRendered.

Returns the if property of this component.

public void
removeActionListener(final ActionListener
The ActionListener to be removed
listener
)

Implements jakarta.faces.component.ActionSource.removeActionListener.

Remove an existing ActionListener (if any) from the set of listeners interested in being notified when ActionEvents occur.

public void
setActionExpression(final MethodExpression
the action expression.
actionExpression
)

Overrides default jakarta.faces.component.ActionSource.setActionExpression.

Set the MethodExpression pointing at the appication action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property.

public void
setImmediate(final boolean
The new immediate execution flag
immediate
)

Implements jakarta.faces.component.ActionSource.setImmediate.

Set the "immediate execution" flag for this UIComponent.

private void
public void
setOnPostback(final boolean
the onPostback flag.
onPostback
)

Controls whether or not this component operates on postback.

public void
setPhase(final String
the phase id (as string value).
phase
)

Attempt to set the lifecycle phase in which this instance will queue its ActionEvent.

public void
setRendered(final boolean
the new value of the property.
condition
)

Overrides jakarta.faces.component.UIComponentBase.setRendered.

Sets the if property of this component.

Inherited from jakarta.faces.component.UIComponentBase:
addClientBehavioraddFacesListenerclearInitialStateencodeBeginencodeChildrenencodeEndfindComponentgetAttributesgetChildCountgetChildrengetClientBehaviorsgetClientIdgetDefaultEventNamegetDescriptorMapgetEventNamesgetFacesContextgetFacesListenersgetFacetgetFacetCountgetFacetsgetFacetsAndChildrengetIdgetListenersForEventClassgetParentgetPassThroughAttributesgetRenderergetRendererTypegetRendersChildreninvokeOnComponentisTransientmarkInitialStateprocessDecodesprocessRestoreStateprocessSaveStateprocessUpdatesprocessValidatorsqueueEventremoveFacesListenerrestoreAttachedStaterestoreStatesaveAttachedStatesaveStatesetIdsetParentsetRendererTypesetTransientsubscribeToEventunsubscribeFromEvent

Field Detail

COMPONENT_FAMILYback to summary
public static final String COMPONENT_FAMILY

The standard component family for this component.

COMPONENT_TYPEback to summary
public static final String COMPONENT_TYPE

The standard component type for this component.

UIVIEWACTION_BROADCASTback to summary
private static final String UIVIEWACTION_BROADCAST
UIVIEWACTION_EVENT_COUNTback to summary
private static final String UIVIEWACTION_EVENT_COUNT

Constructor Detail

UIViewActionback to summary
public UIViewAction()

Create a new UIViewAction instance with default property values.

Method Detail

addActionListenerback to summary
public void addActionListener(final ActionListener listener)

Implements jakarta.faces.component.ActionSource.addActionListener.

Doc from jakarta.faces.component.ActionSource.addActionListener.

Add a new ActionListener to the set of listeners interested in being notified when ActionEvents occur.

Parameters
listener:ActionListener

The ActionListener to be added

Annotations
@Override
Since
2.2
broadcastback to summary
public void broadcast(final FacesEvent event) throws AbortProcessingException

Overrides jakarta.faces.component.UIComponentBase.broadcast.

Enable the method invocation specified by this component instance to return a value that performs navigation, similar in spirit to UICommand#broadcast.

Take no action and return immediately if any of the following conditions are true.

  • The response has already been marked as complete.

  • The current UIViewRoot is different from the event's source's UIViewRoot.

Save a local reference to the viewId of the current UIViewRoot. For discussion, let this reference be viewIdBeforeAction.

Obtain the ActionListener from the jakarta.faces.application.Application. Wrap the current FacesContext in an implementation of jakarta.faces.context.FacesContextWrapper that overrides the FacesContext#renderResponse method such that it takes no action. Set the current FacesContext to be the FacesContextWrapper instance. Make it so a call to isProcessingBroadcast on the current FacesContext will return true. This is necessary because the jakarta.faces.application.NavigationHandler will call this method to determine if the navigation is happening as the result of a UIViewAction. Invoke ActionListener#processAction. In a finally block, restore the original FacesContext, make it so a call to isProcessingBroadcast on the current context will return false and discard the wrapper.

If the response has been marked as complete during the invocation of processAction(), take no further action and return. Otherwise, compare viewIdBeforeAction with the viewId of the UIViewRoot on the FacesContext after the invocation of processAction(). If the two viewIds are the same and no more UIViewAction events have been queued by a call to decode, call FacesContext#renderResponse and return. It is possible to detect the case where no more UIViewAction events have been queued because the number of such events queued has been noted in the specification for decode. Otherwise, execute the lifecycle on the new UIViewRoot.

Parameters
event:FacesEvent

FacesEvent to be broadcast

Annotations
@Override
Exceptions
AbortProcessingException:
Signal the Jakarta Faces implementation that no further processing on the current event should be performed
IllegalArgumentException:
if the implementation class of this FacesEvent is not supported by this component
NullPointerException:
if event is null
Since
2.2
decodeback to summary
public void decode(final FacesContext context)

Overrides jakarta.faces.component.UIComponentBase.decode.

Override behavior from the superclass to queue an ActionEvent that may result in the invocation of the action or any actionListeners that may be associated with this instance.

Take no action if any of the following conditions are true:

  • The current request is a postback and the instance has been configured to not operate on postback. See isOnPostback.

  • The condition stated in the if property evaluates to false. See isRendered

    .

Instantiate an ActionEvent, passing this component instance as the source. Set the phaseId property of the ActionEvent as follows.

Queue the event with a call to queueEvent. Keep track of the number of events that are queued in this way on this run through the lifecycle. This information is necessary during processing in broadcast.

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.decode.

FacesContext for the request we are processing

Annotations
@Override
Since
2.2
decrementEventCountAndReturnTrueIfZeroback to summary
private boolean decrementEventCountAndReturnTrueIfZero(FacesContext context)
getActionExpressionback to summary
public MethodExpression getActionExpression()

Overrides default jakarta.faces.component.ActionSource.getActionExpression.

Doc from jakarta.faces.component.ActionSource.getActionExpression.

Return the MethodExpression pointing at the application action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property.

The default implementation throws UnsupportedOperationException and is provided for the sole purpose of not breaking existing applications that extend ActionSource. Historically this method was declared in ActionSource2 for precisely this reason but default methods in interfaces weren't supported.

Returns:MethodExpression

the action expression.

Annotations
@Override
Since
2.2
getActionListenersback to summary
public ActionListener[] getActionListeners()

Implements jakarta.faces.component.ActionSource.getActionListeners.

Doc from jakarta.faces.component.ActionSource.getActionListeners.

Return the set of registered ActionListeners for this ActionSource instance. If there are no registered listeners, a zero-length array is returned.

Returns:ActionListener[]

the action listeners, or a zero-length array.

Annotations
@Override
Since
2.2
getFamilyback to summary
public String getFamily()

Implements abstract jakarta.faces.component.UIComponent.getFamily.

Doc from jakarta.faces.component.UIComponent.getFamily.

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 appropriate Renderer for this component instance. Note this method should NOT return null

Returns:String

the component family (not null).

Annotations
@Override
getPhaseback to summary
public String getPhase()

Returns the name of the lifecycle phase in which the action is to be queued.

Returns:String

the phase (as string).

Since
2.2
getPhaseIdback to summary
private PhaseId getPhaseId()
getViewRootOfback to summary
private UIViewRoot getViewRootOf(final FacesEvent e)
incrementEventCountback to summary
private void incrementEventCount(FacesContext context)
isImmediateback to summary
public boolean isImmediate()

Implements jakarta.faces.component.ActionSource.isImmediate.

If the value of the component's immediate attribute is true, the action will be invoked during the Apply Request Values Jakarta Faces lifecycle phase. Otherwise, the action will be invoked during the Invoke Application phase, the default behavior. The phase can be set explicitly in the phase attribute, which takes precedence over the immediate attribute.

Returns:boolean

Doc from jakarta.faces.component.ActionSource.isImmediate.

true if immediate, false otherwise.

Annotations
@Override
Since
2.2
isOnPostbackback to summary
public boolean isOnPostback()

If true this component will operate on postback.

Returns:boolean

true if operating upon postback, false otherwise.

Since
2.2
isProcessingBroadcastback to summary
public static boolean isProcessingBroadcast(FacesContext context)

Returns true if the current request processing lifecycle is in the midst of processing the broadcast of an event queued during a call to decode. The implementation of broadcast is responsible for ensuring that calls to this method accurately reflect this fact.

Parameters
context:FacesContext

FacesContext for the current request

Returns:boolean

true is currently processing broadcast, false otherwise.

Since
2.2
isRenderedback to summary
public boolean isRendered()

Overrides jakarta.faces.component.UIComponentBase.isRendered.

Returns the if property of this component. If true then this component should take the actions specified in the decode method.

Returns:boolean

true if it should take the actions, false otherwise.

Annotations
@Override
Since
2.2
removeActionListenerback to summary
public void removeActionListener(final ActionListener listener)

Implements jakarta.faces.component.ActionSource.removeActionListener.

Doc from jakarta.faces.component.ActionSource.removeActionListener.

Remove an existing ActionListener (if any) from the set of listeners interested in being notified when ActionEvents occur.

Parameters
listener:ActionListener

The ActionListener to be removed

Annotations
@Override
Since
2.2
setActionExpressionback to summary
public void setActionExpression(final MethodExpression actionExpression)

Overrides default jakarta.faces.component.ActionSource.setActionExpression.

Doc from jakarta.faces.component.ActionSource.setActionExpression.

Set the MethodExpression pointing at the appication action to be invoked, if this UIComponent is activated by the user, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate 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 extend ActionSource. Historically this method was declared in ActionSource2 for precisely this reason but default methods in interfaces weren't supported.

Parameters
actionExpression:MethodExpression

the action expression.

Annotations
@Override
Since
2.2
setImmediateback to summary
public void setImmediate(final boolean immediate)

Implements jakarta.faces.component.ActionSource.setImmediate.

Doc from jakarta.faces.component.ActionSource.setImmediate.

Set the "immediate execution" flag for this UIComponent.

Parameters
immediate:boolean

The new immediate execution flag

Annotations
@Override
Since
2.2
setIsProcessingUIViewActionBroadcastback to summary
private void setIsProcessingUIViewActionBroadcast(FacesContext context, boolean value)
setOnPostbackback to summary
public void setOnPostback(final boolean onPostback)

Controls whether or not this component operates on postback.

Parameters
onPostback:boolean

the onPostback flag.

Since
2.2
setPhaseback to summary
public void setPhase(final String phase)

Attempt to set the lifecycle phase in which this instance will queue its ActionEvent. Pass the argument phase to PhaseId#phaseIdValueOf. If the result is not one of the following values, FacesException must be thrown.

If set, this value takes precedence over the immediate flag.

Parameters
phase:String

the phase id (as string value).

Since
2.2
setRenderedback to summary
public void setRendered(final boolean condition)

Overrides jakarta.faces.component.UIComponentBase.setRendered.

Sets the if property of this component.

Parameters
condition:boolean

the new value of the property.

Annotations
@Override
Since
2.2
jakarta.faces.component back to summary

private Class UIViewAction.InstrumentedFacesContext

extends FacesContextWrapper
Class Inheritance

A FacesContext delegator that gives us the necessary controls over the FacesContext to allow the execution of the lifecycle to accomodate the UIViewAction sequence.

Field Summary

Modifier and TypeField and Description
private Boolean
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public UIViewAction.InstrumentedFacesContext
public UIViewAction.InstrumentedFacesContext
public UIViewAction.InstrumentedFacesContext
public UIViewRoot
getViewRoot()

Overrides jakarta.faces.context.FacesContextWrapper.getViewRoot.

The default behavior of this method is to call FacesContext#getViewRoot() on the wrapped FacesContext object.

public boolean
isPostback()

Overrides jakarta.faces.context.FacesContextWrapper.isPostback.

The default behavior of this method is to call FacesContext#isPostback() on the wrapped FacesContext object.

public UIViewAction.InstrumentedFacesContext
pushViewIntoRequestMap()

Make it look like we have dispatched a request using the include method.

public void
renderResponse()

Overrides jakarta.faces.context.FacesContextWrapper.renderResponse.

The default behavior of this method is to call FacesContext#renderResponse() on the wrapped FacesContext object.

public void
public void
set()

public void
setViewRoot(final UIViewRoot
The new component UIViewRoot component
viewRoot
)

Overrides jakarta.faces.context.FacesContextWrapper.setViewRoot.

The default behavior of this method is to call FacesContext#setViewRoot(UIViewRoot) on the wrapped FacesContext object.

Inherited from jakarta.faces.context.FacesContextWrapper:
addMessagegetApplicationgetAttributesgetClientIdsWithMessagesgetCurrentPhaseIdgetELContextgetExceptionHandlergetExternalContextgetLifecyclegetMaximumSeveritygetMessageListgetMessageListgetMessagesgetMessagesgetNamingContainerSeparatorChargetPartialViewContextgetRenderKitgetRenderResponsegetResourceLibraryContractsgetResponseCompletegetResponseStreamgetResponseWritergetWrappedisProcessingEventsisProjectStageisReleasedisValidationFailedreleaseresponseCompletesetCurrentPhaseIdsetExceptionHandlersetProcessingEventssetResourceLibraryContractssetResponseStreamsetResponseWritervalidationFailed

Field Detail

postbackback to summary
private Boolean postback
renderedResponseControlDisabledback to summary
private boolean renderedResponseControlDisabled
viewRootClearedback to summary
private boolean viewRootCleared

Constructor Detail

InstrumentedFacesContextback to summary
public InstrumentedFacesContext(final FacesContext wrapped)

Method Detail

clearPostbackback to summary
public UIViewAction.InstrumentedFacesContext clearPostback()
clearViewRootback to summary
public UIViewAction.InstrumentedFacesContext clearViewRoot()
disableRenderResponseControlback to summary
public UIViewAction.InstrumentedFacesContext disableRenderResponseControl()
getViewRootback to summary
public UIViewRoot getViewRoot()

Overrides jakarta.faces.context.FacesContextWrapper.getViewRoot.

Doc from jakarta.faces.context.FacesContextWrapper.getViewRoot.

The default behavior of this method is to call FacesContext#getViewRoot() on the wrapped FacesContext object.

Returns:UIViewRoot

Doc from jakarta.faces.context.FacesContext.getViewRoot.

UIViewRoot instance.

Annotations
@Override
isPostbackback to summary
public boolean isPostback()

Overrides jakarta.faces.context.FacesContextWrapper.isPostback.

Doc from jakarta.faces.context.FacesContextWrapper.isPostback.

The default behavior of this method is to call FacesContext#isPostback() on the wrapped FacesContext object.

Returns:boolean

Doc from jakarta.faces.context.FacesContext.isPostback.

the boolean indicating whether this request is a post one.

Annotations
@Override
pushViewIntoRequestMapback to summary
public UIViewAction.InstrumentedFacesContext pushViewIntoRequestMap()

Make it look like we have dispatched a request using the include method.

renderResponseback to summary
public void renderResponse()

Overrides jakarta.faces.context.FacesContextWrapper.renderResponse.

Doc from jakarta.faces.context.FacesContextWrapper.renderResponse.

The default behavior of this method is to call FacesContext#renderResponse() on the wrapped FacesContext object.

Annotations
@Override
restoreback to summary
public void restore()
setback to summary
public void set()
setViewRootback to summary
public void setViewRoot(final UIViewRoot viewRoot)

Overrides jakarta.faces.context.FacesContextWrapper.setViewRoot.

Doc from jakarta.faces.context.FacesContextWrapper.setViewRoot.

The default behavior of this method is to call FacesContext#setViewRoot(UIViewRoot) on the wrapped FacesContext object.

Parameters
viewRoot:UIViewRoot

Doc from jakarta.faces.context.FacesContext.setViewRoot.

The new component UIViewRoot component

Annotations
@Override
jakarta.faces.component back to summary

pack-priv final Enum UIViewAction.PropertyKeys

extends Enum<UIViewAction.PropertyKeys>
Class Inheritance

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final UIViewAction.PropertyKeys
public static final UIViewAction.PropertyKeys
private String
public static final UIViewAction.PropertyKeys
public static final UIViewAction.PropertyKeys
public static final UIViewAction.PropertyKeys

Constructor Summary

AccessConstructor and Description
private
private
PropertyKeys(final String name)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static UIViewAction.PropertyKeys
public static UIViewAction.PropertyKeys[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

actionExpressionback to summary
public static final UIViewAction.PropertyKeys actionExpression
immediateback to summary
public static final UIViewAction.PropertyKeys immediate
nameback to summary
private String name

Hides java.lang.Enum.name.

onPostbackback to summary
public static final UIViewAction.PropertyKeys onPostback
phaseback to summary
public static final UIViewAction.PropertyKeys phase
renderedAttrback to summary
public static final UIViewAction.PropertyKeys renderedAttr

Constructor Detail

PropertyKeysback to summary
private PropertyKeys()
PropertyKeysback to summary
private PropertyKeys(final String name)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static UIViewAction.PropertyKeys valueOf(String name)
valuesback to summary
public static UIViewAction.PropertyKeys[] values()