Class ViewAction
- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- jakarta.faces.component.UIViewAction
-
- org.omnifaces.component.input.ViewAction
-
- All Implemented Interfaces:
ActionSource
,ActionSource2
,PartialStateHolder
,StateHolder
,TransientStateHolder
,ComponentSystemEventListener
,FacesListener
,SystemEventListenerHolder
,EventListener
public class ViewAction extends UIViewAction
The
<o:viewAction>
is a component that extends the standard<f:viewAction>
and changes theif
attribute to be evaluated duringINVOKE_APPLICATION
phase instead of theAPPLY_REQUEST_VALUES
phase. This allows developers to let theif
attribute check the converted and validated model values before performing the view action, which results in much more intuitive behavior.In below example, the
FooConverter
may convert a non-null parameter tonull
without causing a validation or conversion error, and the intent is to redirect the current page tootherpage.xhtml
when the converted result isnull
.<f:viewParam name="foo" value="#{bean.foo}" converter="fooConverter" /> <f:viewAction action="otherpage" if="#{bean.foo eq null}" />
This is however not possible with standard
<f:viewAction>
as it evaluates theif
attribute already before the conversion has taken place. This component solves that by postponing the evaluation of theif
attribute to theINVOKE_APPLICATION
phase.<f:viewParam name="foo" value="#{bean.foo}" converter="fooConverter" /> <o:viewAction action="otherpage" if="#{bean.foo eq null}" />
Only when you set
immediate="true"
, then it will behave the same as the standard<f:viewAction>
.Usage
You can use it the same way as
<f:viewAction>
, you only need to changef:
too:
.<o:viewAction action="otherpage" if="#{bean.property eq null}" />
Messaging
You can use the
message
attribute to add a global flash warning message.<o:viewAction ... message="Please use a valid link from within the site" />
Note that the message will only be shown when the redirect has actually taken place. The support was added in OmniFaces 3.2.
- Since:
- 2.2
- Author:
- Bauke Scholtz
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.input.ViewAction".-
Fields inherited from class jakarta.faces.component.UIViewAction
COMPONENT_FAMILY
-
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 Constructor Description ViewAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
broadcast(FacesEvent event)
Only broadcast the action event whenUIViewAction.isRendered()
returnstrue
.String
getMessage()
Returns the global flash warning message to be shown in the redirected page.boolean
isRendered()
Returnstrue
if theimmediate="true"
attribute is not set, otherwise delegate to super, hereby maintaining the original behavior ofimmediate="true"
.void
setMessage(String message)
Sets the global flash warning message to be shown in the redirected page.-
Methods inherited from class jakarta.faces.component.UIViewAction
addActionListener, decode, getAction, getActionExpression, getActionListener, getActionListeners, getFamily, getPhase, isImmediate, isOnPostback, isProcessingBroadcast, removeActionListener, setAction, setActionExpression, setActionListener, setImmediate, setOnPostback, setPhase, setRendered
-
Methods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, clearInitialState, 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, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendererType, setTransient, setValueBinding, 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 Detail
-
COMPONENT_TYPE
public static final String COMPONENT_TYPE
The component type, which is "org.omnifaces.component.input.ViewAction".- See Also:
- Constant Field Values
-
-
Method Detail
-
broadcast
public void broadcast(FacesEvent event)
Only broadcast the action event whenUIViewAction.isRendered()
returnstrue
. The default implementation will always broadcast. TheUIViewAction.isRendered()
is by default only considered duringUIViewAction.decode(jakarta.faces.context.FacesContext)
.If the action event performs any redirect, then add any
getMessage()
as a global flash warning message.- Overrides:
broadcast
in classUIViewAction
-
isRendered
public boolean isRendered()
Returnstrue
if theimmediate="true"
attribute is not set, otherwise delegate to super, hereby maintaining the original behavior ofimmediate="true"
.- Overrides:
isRendered
in classUIViewAction
-
getMessage
public String getMessage()
Returns the global flash warning message to be shown in the redirected page.- Returns:
- The global flash warning message to be shown in the redirected page.
- Since:
- 3.2
-
setMessage
public void setMessage(String message)
Sets the global flash warning message to be shown in the redirected page.- Parameters:
message
- The global flash warning message to be shown in the redirected page.- Since:
- 3.2
-
-