Taskflows are a very useful feature in Oracle ADF which provide a modular approach for defining control flow in an application. It allows to create application flow graphs which can be tied together to build the complete application. So instead of considering an application as a collection of different JSF pages, in ADF we would consider an application as a collection of different taskflows.
ADF Taskflows come in two forms:
- Bounded Taskflow
- Unbounded Taskflow
Unbounded Taskflow: A set of activities (JSF Pages/views), 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 Taskflow: 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.
A bounded taskflow:
- has single entry point.
- zero or more exit points.
- may accept input parameters.
- may generate return value.
- has its own memory scope called pageflow scope.
The memory scope of a bounded taskflow called pageflow scope allows the developer to declare java bean classes in that scope making it available/accessible across all the JSF pages within the taskflow.
In this article we will look at how to create ADF bounded taskflow using JDeveloper. I am using JDeveloper Studio Edition Version 18.104.22.168.0 for this article.
Creating a new ADF Web Application:
From the Application Navigator click on New Application and you should see this popup:
Select Fusion Web Application(ADF) and click on Ok to get the next popup:
Enter the Application name as BoundedTaskFlowCreation and then click on Finish button to create a new application. Once you have created a new application you would get this view:
With this you have your new ADF application setup. You would see 2 projects: Model and ViewController (assuming you didn’t change the defaults apart from adding new application name while creating the new application). The Model project contains all the code which deals with ADF Data binding layer called- ADFBC and ViewController project contains all the view related code like the JSF pages, the java classes which act as managed beans for those JSF pages.
Creating a new bounded taskflow
Right click on the ViewController project and click on New:
In the new window select JSF/Facelets from the Web Tier categories in the right and then select ADF Taskflow from the right and click on Ok as shown below:
In the Create Taskflow window enter the File Name which would be the name of the bounded taskflow, let the Directory be default, check the Create as Bounded Taskflow check box and uncheck the Create with Page Fragments checkbox. After you have entered the details, your screen would be more or less like:
A bounded taskflow is represented by an XML config file which contains the views/pages part of the taskflow, the control flow structure i.e navigation from one page/view to another which can also include conditional flows, any java bean classes which are referenced by the views/pages within the taskflow which are called as Managed beans. And creating a bounded taskflow with pagefragements will not allow it to be launched independently and hence I am creating a bounded taskflow without page fragments. A bounded taskflow with page fragments would allow us to create only JSFF files i.e JSF fragment files.
Once you have clicked on Ok, you will be shown the Bounded Taskflow Diagrammatic view as shown below:
Generally lot of the work with taskflows can be easily done using the diagrammatic view. Most of us should be familiar with the GUI builders which are used for creating Swing applications or Flex applications. When we drag and drop components on the taksflow diagram, there is code generated in the XML which corresponds to the components added. You should be able to see the component palette on the right hand side and the Properties Inspector window at the bottom (the screenshot shown above shows the two windows). If you are not able to see these windows, you can always add them from the View menu.
In the component palette you can see a plethora of components which can be added to the taskflow. Search for View and then drag drop the View(ADF Task Flow.Components) on to the taskflow area. And then enter the name of the view as: firstPage. You should now see a view component in the taskflow as shown below:
Note that after adding the View component no JSF/JSP page has been created. To create a JSF page for that view double click on the view component to get the following popup:
You can select/choose from the Layouts or just select the Blank option to create a new JSF page. In the same way described above add another view: secondPage.
One can see a light green shade around firstPage component. This indicates that the default activity for the bounded taskflow is firstPage. One can change the default activity by selecting the bounded taskflow and changing the Default Activity property from the Property Inspector window.
Now I want to navigate from firstPage to secondPage drag and drop the Control Flow case by dragging from firstPage to secondPage and name that navigation as gotoSecond. The taskflow diagram would be as shown below:
And after all this lets have a look at the XML for the first-bounded-task-flow.xml:
<?xml version="1.0" encoding="windows-1252" ?> <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2"> <task-flow-definition id="first-bounded-task-flow"> <default-activity>firstPage</default-activity> <view id="firstPage"> <page>/firstPage.jsf</page> </view> <view id="secondPage"> <page>/secondPage.jsf</page> </view> <control-flow-rule id="__1"> <from-activity-id>firstPage</from-activity-id> <control-flow-case id="__2"> <from-outcome>gotoSecond</from-outcome> <to-activity-id>secondPage</to-activity-id> </control-flow-case> </control-flow-rule> </task-flow-definition> </adfc-config>
Now double click on firstPage view to get the firstPage.jsf and switch to the Source view. Now add the following code to the firstPage.jsf between the af:form tag:
<af:outputText value="This is first page" id="ot1"/> <af:commandButton text="Goto Second Page" id="cb1" action="gotoSecond"/>
The above code shows- an output text to show some text and a button to navigate to the next page. The action attribute above is assigned the name of the control flowcase created above.
Now go back to the first-bounded-task-flow and double click on the secondPage view to get secondPage.jsf. In the secondPage.jsf add the following code between af:form tag:
Now you have a bounded taskflow and go to the bounded taskflow and right click and then click on Run for the application to be deployed. It will run an Integrated Web Logic server and deploy the application to it.
I have uploaded the project for anyone who wants to look into the project.
If you are interested in receiving the future java articles and tips from us, please subscribe here.
If you have any doubts on ADF or Java Server faces (JSF), please post it in the comments section.