Thursday, 24 October 2013

14 Getting Started with ADF Task Flows

14 Getting Started with ADF Task Flows
This chapter describes how to create ADF task flows that enable navigation,
encapsulation, reuse, managed bean lifecycles, and transactions within an application.
It includes the basic steps for creating a task flow diagram, adding activities and
control flows to it, and running the finished task flow.
This chapter includes the following sections:
■ Section 14.1, "Introduction to ADF Task Flows"
■ Section 14.2, "Creating a Task Flow"
■ Section 14.3, "Adding Activities to a Task Flow"
■ Section 14.4, "Testing ADF Task Flows"
■ Section 14.5, "Refactoring to Create New ADF Task Flows and Templates"
■ Section 14.6, "What You Should Know About Task Flow Constraints"
14.1 Introduction to ADF Task Flows
ADF task flows provide a modular approach for defining control flow in an application.
Instead of representing an application as a single large JSF page flow, you can break it
up into a collection of reusable task flows. Each task flow contains a portion of the
application's navigational graph.
The nodes in the task flows are activities.
An activity node represents a simple logical operation such as displaying a page, executing application logic, or calling another task flow.
The transactions between the activities are called control flow cases.
Figure 14–1 shows two view activities called Create and Confirm. These view activities are similar to page nodes within a JSF page flow.
Figure 14–1 ADF Task Flow

Task flows can invoke managed beans. For more information about defining managed
beans for use with a task flow, the supported memory scopes, and other related
information, see Section 14.2.4, "What You May Need to Know About Memory Scope
for Task Flows" and Section 20.4, "Using a Managed Bean in a Fusion Web
Application".
14.1.1 Task Flow Advantages
ADF task flows offer significant advantages over standard JSF page flows, as
described in Table 14–1.
14.1.2 Task Flow Types
The two types of ADF task flow are:
Unbounded task flow: A set of activities, control flow rules, and managed beans
that interact to allow a user to complete a task. An ADF unbounded task flow
consists of all activities and control flows in an application that are not included
within any bounded task flow.
Bounded task flow: A specialized form of task flow that, in contrast to an
unbounded task flow, has a single entry point and zero or more exit points. It
contains its own set of private control flow rules, activities, and managed beans.
An ADF bounded task flow allows reuse, parameters, transaction management,
and reentry.
For a description of the activity types that you can add to an ADF unbounded or
bounded task flow see Chapter 15, "Working with Task Flow Activities".
A bounded task flow is also known as a task flow definition. By default, JDeveloper
proposes the following filename for the source file of a bounded task flow:
task-flow-definitionN.xml
where N is a number that increments each time that you create a new bounded
task flow.
A typical application is a combination of an unbounded and one or more bounded
task flows. For example, JDeveloper, by default, creates an empty unbounded task
flow (source file name is adfc-config.xml) when you create a Fusion web
application using the Fusion Web Application template. At runtime, the Fusion web
application can call bounded task flows from activities that you added to this
unbounded task flow.
As shown in Figure 14–2, the first activity to execute in an application is often a view
activity within an ADF unbounded task flow. A view activity represents a JSF page
that displays as part of the application. The activity shown in Figure 14–2 starts with
the Home view activity and then calls a bounded task flow. The calltoLogin_
taskFlow activity calls a bounded task flow that enables a user to log into the
application.
You can also design an application in which all application activities reside within the
ADF unbounded flow. This mimics a Struts or JSF application, but doesn't take
advantage of ADF bounded task flow functionality. To take full advantage of task flow
functionality, use ADF bounded task flows.
14.1.2.1 Unbounded Task Flows
A Fusion web application always contains an ADF unbounded task flow, which contains
the entry point or points to the application. Figure 14–3 displays the diagram for the
unbounded task flow from the Fusion Order Demo Application. This task flow
contains a number of view activities that are all entry points to the application.
You typically use an unbounded instead of a bounded task flow if:
 You want to take advantage of ADF Controller features not offered by bounded
    task flows, such as bookmarkable view activities. For more information, see
    Section 15.2.3, "Bookmarking View Activities".
■ The task flow will not be called by another task flow.
■ The application has multiple points of entry. In Figure 14–3, the task flow can be
    entered through any of the pages represented by the view activity icons on the
    unbounded task flows.
    Pages are associated with view activities. The icon for a view activity displays a
    page image like this:
    image // to do
■ You want to bookmark more than one activity on the task flow. See Section 15.2.3,
   "Bookmarking View Activities" for more information.
An unbounded task flow cannot declaratively specify parameters. In addition, it
cannot contain a default activity, an activity designated as the first to run in the
unbounded task flow. This is because an unbounded task flow does not have a single
point of entry. To perform any of these requires an ADF bounded task flow.

In order to take advantage of completely declarative ADF Controller transaction and
reentry support, use a bounded rather than an unbounded task flow.
14.1.2.2 Bounded Task Flows
An ADF bounded task flow is used to encapsulate a reusable portion of an application.
A bounded task flow is similar to a Java method in that it:
■ Has a single entry point
■ May accept input parameters
■ May generate return values
■ Has its own collection of activities and control flow rules
■ Has its own memory scope and managed bean lifespan (a page flow scope
instance)
The checkout-task-flow activity in Figure 14–3 is a call to an ADF bounded task
flow. An unbounded task flow can call an ADF bounded task flow, but cannot be
called by another task flow. A bounded task flow can call another bounded task flow,
which can call another and so on. There is no limit to the depth of the calls.
The checkout process is created as a separate ADF bounded task flow, as shown in
Figure 14–4.//to do


The reasons for creating the (checkout-task-flow activity as a called) bounded task
flow are:
The bounded task flow always specifies a default activity, a single point of entry
that must execute immediately upon entry of the bounded task flow.
In the checkout task flow, the activity labeled reconcileShoppingCart invokes
a method that returns a list of items that an anonymous user (one who has not yet
logged in to the application) may have chosen to purchase. Any items chosen
before authentication are included in the shopping cart after the user has logged
in. Because it is the default activity, the method is always invoked before the
shopping cart order page displays.
checkout-task-flow is reusable. For example, it can be included in other
applications requiring an item checkout process. The bounded task flow can also
be reused within the same application.
■ Any managed beans you decide to use within checkout-task-flow can be
specified in page flow scope, so are isolated from the rest of the application.
The main features of ADF bounded task flows are summarized in
Table 14–2.
14.1.3 Control Flows
A task flow consists of activities and control flow cases that define the transitions
between activities. In Figure 14–5, the control flow labeled toView2 defines the
transition between ViewActivity1 and ViewActivity2. ViewActivity1
displays before ViewActivity2 when the task flow in
Figure 14–5 executes.

No comments:

Post a Comment