Saturday, 30 January 2016

Use of Router in ADF Task Flow

Explanation: The Router activity is used to check for a condition and then direct the control to the appropriate flow. When we drag-and-drop the router component, the Router activity is added to the task low which has the following properties:
  • default-outcome: This determines the default outcome of the router.
  • expression: This is used to provide the expression that will be evaluated at runtime to determine which outcome has to be chosen for the flow. There can be many expression properties, but there will always be one default-outcome and it is mandatory to set the default outcome. The EL expression is used at design time to provide the expression. For example:
<expression>#{pageFlowScope.employweeBean.count == 1}</expression> <outcome>department</outcome>
If the count variable in employeeBean is evaluated to 1, then the control is taken to the department flow as outcome.
Requirement: I have a bounded task flow task-flow-definition.xml. In this task flow I have three view activities: view1, view2, and view3. Also I have one router named as router1. We have the following control flow cases as shown below:
  1. Control flow case gotoRouter from view1 to router1.
  2. Control flow case gotoPage1 from router1 to view2.
  3. Control flow case gotoPage2 from router1 to view3.
  4. Control flow case backFromPage1 from view2 to view1.
  5. Control flow case backFromPage2 from view3 to view1.
Double click each of these view activities to create the view1.jsff, view2.jsff, and view3.jsff.
In view1.jsff we have one inputText to enter User Name and one button named as Login. When user pass some User Name in the inputText and click on the Login button it will go to the router1 and based on the User Name we typed it will decide which view to be called (view2.jsff or view3.jsff).
Also in each of view.jsff and view3.jsff we will have one button to go back to the view.jsff. How to achieve this functionality.
Solution: For solution to the above requirement follow the steps as shown below:

Step 1: Create a New ADF Fusion Web Application named as RouterDemo.

Step 2: Create a bounded task flow task-flow-definition.xml. Inside the bounded task flow drag and drop three view activites: view1, view2, and view3 from the component palette. Double click each of these view activities to create the view1.jsff, view2.jsff, and view3.jsff.

Drag and drop router named as router1 in the bounded task flow from the component palette.

Also drag and drop the corresponding control flow cases as shown in the below diagram:

Step 3: Open view1.jsff and drag and drop one af:inputText. Label the af:inputText as User Name and create the binding for the af:inputText as binding="#{pageFlowScope.MyBean.unameBinding}"

Please note we will not write any code in MyBean.java other then the af:inputText binding code which gets generated automatically.

Drag and drop one af:button and named the button as Login. Set te action of the af:button as action="gotoRouter".

Thus the complete view.jsff code is shown below:

Step 4: Open view2.jsff and drag and drop one af:button and set the text and action as text="Back button from Page1" action="backFromPage1". Surround the button with af:panelGroupLayout.

Thus the complete view2.jsff code is shown below

Step 5: Open view3.jsff and drag and drop one af:button and set the text and action as text="Back button from Page2" action="backFromPage2". Surround the button with af:panelGroupLayout.

Thus the complete view3.jsff code is shown below

Step 6: Open task-flow-definition.xml and click on router1. Now set the following properties for the router1 as shown below:

Here it is mandatory to give the default outcome. When the page run and if we type the User Name as Susanto then the view2.jsff is called. If we type User Name as Nilesh and click on Login then view3.jsff is called. If we don’t type any User Name and click on Login then by default view2.jsff is called.

Step 6: Create a launch.jspx page and drag and drop task-flow-definition.xml as a region on the launch.jspx page as shown below:

Step 7: Save all and run the launch.jspx. Thus the ran application is shown below:

Here if we don’t write any User Name and click on Login button then by default the view2.jsff is called. If we type User Name as Susanto and click on Login then view2.jsff is called as shown below:

On click of Back button from Page1 we get redirected to view1.jsff.

If we type User Name as Nilesh and click on Login then view3.jsff is called as shown below:

On click of Back button from Page2 we get redirected to view1.jsff.

Hence, the solution to our requirement.

If you like the post please comment, share and like me on Facebook.


Thanks & Regards,
Susanto Paul