Java Reference
In-Depth Information
You will learn more about the flow definition in the section below entitled “Navigating View Nodes”. The code that
was previously listed for intermediateFlow.xhtml demonstrates how a link could be utilized to exit a flow.
The Flow Managed Bean
A flow contains its own managed bean annotated as @FlowScoped , which differs from @SessionScoped because the data
can be accessed only by other view nodes belonging to the flow. The @FlowScoped annotation relies upon contexts and
dependency injection (CDI), because FlowScope is a CDI scope that causes the runtime to consider classes with the
@FlowScoped annotation to be in the scope of the specified flow. A @FlowScoped bean maintains a life cycle that begins
and ends with a flow instance. Multiple flow instances can exist for a single application, and if a user begins a flow
within one browser tab and then opens another, a new flow instance will begin in the new tab. This solution resolves many
lingering issues around sessions and modern browsers, allowing users to open multiple tabs without causing session-based
issues. To maintain separate flow instances, the ClientId is used by JSF to differentiate among multiple instances.
Each flow can contain an initializer and a finalizer, that is, a method that will be invoked when a flow is entered,
and a method that will be invoked when a flow is exited, respectively. To declare an initializer, specify a child element
named <initializer> within the flow definition <faces-flow-definition> . The initializer element can be an EL
expression that declares the managed bean initializer method, as such:
...
<initializer>#{flowBean.initializeIt}></initializer>
...
Similarly, a <finalizer> element can be specified within the flow definition to define the method that will be
called when the flow is exited. The following demonstrates how to set the finalizer to an EL expression declaring the
managed bean finalizer method:
...
<finalizer>#{flowBean.finalizeIt}></finalizer>
...
Flows can contain method calls and variable values that are accessible only via the flow nodes. These methods
and variables should be placed within the FlowScoped bean and used the same as standard managed bean methods
and variables. The main difference is that any variable that is instantiated within a FlowScoped bean is available only
for a single flow instance.
Navigating View Nodes
Flows contain their own navigational rules. These rules can be straightforward and produce a page-by-page
navigation, or they can be complex and include conditional logic. There are a series of elements that can be specified
Table 2-2. Flow Navigational Nodes
Element
Description
view
Navigates to a standard JSF view.
switch
One or more EL expressions that conditionally evaluate to true or false. If true, then navigation
occurs to the specified view node.
flow-return
Outcome determined by the caller of the flow.
flow-call
A call to another flow; creates a nested flow.
method-call
Arbitrary method call that can invoke a method that returns a navigational outcome.
 
 
Search WWH ::




Custom Search