Class FlowHandler
FlowHandler is the main
entry point that enables the runtime to interact with the faces flows
feature. NavigationHandler uses this
class when it needs to make navigational decisions related to flows.
The faces flow feature entirely depends on the ClientWindow feature and also on CDI.
Defining Flows
The implementation must support defining faces flows using the
<flow-definition> element as specified in
the Application
Configuration Resources XML Schema Definition, or by using the
FlowBuilder API. Additional means
of defining flows may be provided by decorating the FlowHandlerFactory.
Managing Flows
View
This is the regular JSF VDL View that has been in the specification since the beginning.
Switch
This is a list of EL expressions. When control is passed to a switch node, each expression in the list is evaluated and the first one that returns
trueis used to define the id of the next node to which control must be passed. If none of the expressions evaluates totrue, control passes to the specified default id.Return
This node type specifies an outcome that is returned to the calling flow.
Method Call
This node type allows invocation of arbitrary application logic at any point in the executiong of the flow. An outcome can be specified that will cause a navigation case to be navigated to after the method has been invoked.
Faces Flow Call
This node type allows one flow to call another flow. The calling flow remains active and is not exited until control returns from the called flow.
The singleton instance of this class must be thread safe, and
therefore must not store any per-user state. Flows are, however,
traversed in a per-user manner, and must be associated with the
current ClientWindow. Furthermore,
Flows may be nested. These requirements strongly suggest managing
the flows with a stack-like runtime data structure, stored in a
per-user fashion and associated with the ClientWindow.
The Flow Graph
Prior versions of the specification defined a flow graph but the only kind of node in the graph was a VDL view. The Faces Flow feature currently defines the following node types.
Edges in the graph are defined by the existing JSF navigation rule system.
Flows and Model Objects
Managed beans annotated with the CDI annotation
FlowScoped must be instantiated upon a user agent's entry
into the named scope, and must be made available for garbage
collection when the user agent leaves the flow.
The flowScope EL implicit object is also
available to store values in the "current" slope. Values stored in
this scope must be made available for garbage collection when the
user agent leaves the flow.
- Since:
- 2.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringComponents that are rendered byRenderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the parameter name for a parameter representing the flow id of the flow that this component will cause to be entered.static final StringComponents that are rendered byRenderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the value of the parameter named byTO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAMEwhen returning from a flow (without entering another flow) using such a component.static final StringComponents that are rendered byRenderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the parameter name for a parameter representing the defining document id of the flow that this component will cause to be entered. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddFlow(FacesContext context, Flow toAdd) Add the argumentFlowto the collection ofFlows known to the current application.abstract voidclientWindowTransition(FacesContext context) Allow for flow transitions in the case of components rendered by the renderers from component-familyjavax.faces.OutcomeTarget.Convenience overload that callsFacesContext.getCurrentInstance()and then calls through togetCurrentFlow(javax.faces.context.FacesContext).abstract FlowgetCurrentFlow(FacesContext context) Return theMapthat backs the#{flowScope}EL implicit object ornullif no flow is currently active.abstract FlowgetFlow(FacesContext context, String definingDocumentId, String id) Return theFlowwhoseidis equivalent to the argumentid, within the scope of the argumentdefiningDocument.abstract StringgetLastDisplayedViewId(FacesContext context) Return the last displayed viewId for the current flow, as returned bygetCurrentFlow(javax.faces.context.FacesContext), ornullif there is no current flow.abstract booleanisActive(FacesContext context, String definingDocument, String id) Returntrueif and only if the flow referenced by the argumentdefiningDocumentandidis currently active.abstract voidpopReturnMode(FacesContext context) Enable the correct handling of navigation when processing a return node.abstract voidpushReturnMode(FacesContext context) Enable the correct handling of navigation when processing a return node.abstract voidtransition(FacesContext context, Flow sourceFlow, Flow targetFlow, FlowCallNode outboundCallNode, String toViewId) Perform a transition in the flow graph for the current user'sClientWindow.
-
Field Details
-
FLOW_ID_REQUEST_PARAM_NAME
Components that are rendered by
Renderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the parameter name for a parameter representing the flow id of the flow that this component will cause to be entered.- Since:
- 2.2
- See Also:
-
TO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME
Components that are rendered by
Renderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the parameter name for a parameter representing the defining document id of the flow that this component will cause to be entered.- Since:
- 2.2
- See Also:
-
NULL_FLOW
Components that are rendered by
Renderersof component-familyjavax.faces.OutcomeTargetmust use this constant as the value of the parameter named byTO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAMEwhen returning from a flow (without entering another flow) using such a component.- Since:
- 2.2
- See Also:
-
-
Constructor Details
-
FlowHandler
public FlowHandler()
-
-
Method Details
-
getCurrentFlowScope
Return the
Mapthat backs the#{flowScope}EL implicit object ornullif no flow is currently active.- Since:
- 2.2
-
getFlow
Return the
Flowwhoseidis equivalent to the argumentid, within the scope of the argumentdefiningDocument.- Parameters:
context- theFacesContextfor the current request.definingDocumentId- An application unique identifier for the document in which the returned flow is defined.id- the id of aFlow, unique within the scope of thedefiningDocument.- Throws:
NullPointerException- if any of the parameters arenull- Since:
- 2.2
-
addFlow
Add the argument
Flowto the collection ofFlows known to the current application. The implementation must be thread safe.- Parameters:
context- theFacesContextfor the current request.toAdd- theFlowto add.- Throws:
NullPointerException- if any of the parameters arenullIllegalStateException- if there is already a flow with the sameidas the argumentFlowwithin the scope of thedefiningDocument.IllegalArgumentException- if theidof the flow to add isnullor the empty string.IllegalArgumentException- if thedefiningDocumentIdof thetoAddisnull.- Since:
- 2.2
-
getCurrentFlow
Return the currently active
Flowfor the argumentFacesContext, ornullif no flow is active. AFlowmust always be associated with exactly oneClientWindow, but aClientWindowmay have multipleFlows.If
pushReturnMode(javax.faces.context.FacesContext)had been called withtrueas the argument before invoking this method, return the preceding flow on the stack instead of the actual current flow, ornullif there is no preceding flow. Otherwise, return the current flow.- Parameters:
context- theFacesContextfor the current request.- Throws:
NullPointerException- if any of the parameters arenull- Since:
- 2.2
-
getCurrentFlow
Convenience overload that calls
FacesContext.getCurrentInstance()and then calls through togetCurrentFlow(javax.faces.context.FacesContext).- Since:
- 2.2
-
getLastDisplayedViewId
Return the last displayed viewId for the current flow, as returned by
getCurrentFlow(javax.faces.context.FacesContext), ornullif there is no current flow.- Parameters:
context- theFacesContextfor the current request.- Throws:
NullPointerException- ifcontextisnull- Since:
- 2.2
-
pushReturnMode
Enable the correct handling of navigation when processing a return node. The default
NavigationHandlerspecification requires calling this method before processing the navigation rules for the flow return, and callingpopReturnMode(javax.faces.context.FacesContext), from afinallyblock, immediately afterward.- Parameters:
context- theFacesContextfor the current request.- Throws:
NullPointerException- ifcontextisnull.- Since:
- 2.2
-
popReturnMode
Enable the correct handling of navigation when processing a return node. The default
NavigationHandlerspecification requires calling this method from afinallyblock, immediately attempting to process the navigation rules in the context of a flow return.- Parameters:
context- theFacesContextfor the current request.- Throws:
NullPointerException- ifcontextisnull.- Since:
- 2.2
-
transition
public abstract void transition(FacesContext context, Flow sourceFlow, Flow targetFlow, FlowCallNode outboundCallNode, String toViewId) Perform a transition in the flow graph for the current user's
ClientWindow. Obtain references to theFlowinstances corresponding to theoriginanddestinationarguments. If theorigin Flowis equal to thedestination Flow, take no action and returnnull. Otherwise, if theoutboundCallNodeargument is non-nullsave aside the outbound parameters. For discussion evaluatedParams is a data structure that stores the evaluated values of any outbound parameters. It is necessary to evaluate these values before popping any flow scopes because the values may refer to scoped instances that need to be passed to the target flow, but will not be available once the new scope is activated. Save aside the outbound parameters using the following algorithm.If the
outboundParametersproperty ofoutboundCallNodeis non-nulland not empty, and theinboundParametersproperty of the target flow is non-nulland not empty, for each entry in the outbound parameters whose name matches an entry in the inbound parameters, evaluate the value of the parameter, and put the evaluated value into evaluatedParams under the corresponding name. Otherwise, consider evaluatedParams to be empty.If the
destination Flowis a sub-flow of theorigin Flowpush thedestination Flowonto the flow data structure and returnthe destination Flow. Otherwise, pop the currentFlowfrom the flow data structure. If thedestination Flowis non-null, make thedestination Flowthe current flow, pushing it onto the data structure. If evaluatedParams is not empty, for each entry, find the corresponding parameter in the target flow's inbound parameters and call itssetValuemethod, passing the value from evaluatedParams.- Parameters:
context- theFacesContextfor the current request.sourceFlow- the currentFlow, ornullif there is no source flow.targetFlow- the destinationFlow, ornullif there is no destination flow.outboundCallNode- the flow call node causing this transition, ornullif this transition is not caused by a flow call.toViewId- the viewId of the view being displayed as a result of this transition. This parameter makes it possible to implementgetLastDisplayedViewId(javax.faces.context.FacesContext).- Throws:
NullPointerException- ifcontextortoViewIdisnull.- Since:
- 2.2
-
clientWindowTransition
Allow for flow transitions in the case of components rendered by the renderers from component-family
javax.faces.OutcomeTarget. These transitions must happen at the front of the request processing lifecycle due to the HTTP GET based nature of such components. Therefore, this method is called from the restore view phase of the lifecycle.Let flowId be the value in the request parameter map for the parameter whose name is given by the value of
FLOW_ID_REQUEST_PARAM_NAME. Let toFlowDocumentId be the value in the request parameter map for the paramater whose name is given by the value ofTO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME. If toFlowDocumentId isnull, take no action and return. Otherwise, let sourceFlow be the return fromgetCurrentFlow(javax.faces.context.FacesContext). Anullvalue indicates there is no current flow, which will be the case if this navigation is trying to enter a flow. If flowId is notnulland toFlowDocumentId is not equal to the value ofNULL_FLOW, let targetFlow be the result of callinggetFlow(javax.faces.context.FacesContext, java.lang.String, java.lang.String), passing toFlowDocumentId and flowId as the last two arguments, respectively. If the result is non-null, let flowCallNode be the return from callingFlow.getFlowCall(javax.faces.flow.Flow)on the sourceFlow, passing targetFlow as the argument. Otherwise, targetFlow and flowCallNode must remainnull, indicating that this is a flow return. CallFacesContext.getViewRoot()and let toViewId be the the return from callingUIViewRoot.getViewId()on it.Call,
transition(javax.faces.context.FacesContext, javax.faces.flow.Flow, javax.faces.flow.Flow, javax.faces.flow.FlowCallNode, java.lang.String), passing the arguments gathered in the preceding algorithm.- Parameters:
context- theFacesContextfor the current request.- Throws:
NullPointerException- ifcontextisnull.- Since:
- 2.2
-
isActive
Return
trueif and only if the flow referenced by the argumentdefiningDocumentandidis currently active.- Parameters:
context- theFacesContextfor the current request.definingDocument- An application unique identifier for the document in which the returned flow is defined.id- the id of aFlow, unique within the scope of thedefiningDocument.- Throws:
NullPointerException- if any of the parameters arenull- Since:
- 2.2
-