Pass custom objects across ADF taskflows (by value or reference)

JDev: 12.2.1.3.0
Source: GitHub

We usually pass along parameters of native data types across ADF task-flow calls. We set up input and output parameters for the source and target task-flows, and we access the variables from the pageFlowScope map.

Absolutely nothing wrong with this approach.

But how about a scenario where we process and populate a POJO variable from the source task-flow, and expect a POJO variable on the target task-flow to be populated via a declarative route?

The Parameters section of a bounded task-flow allows you to set a specific property on its managed bean to which the object being passed across will be assigned.

While passing along an object across task-flows, ADF lets you choose whether you want to pass the object by value or by reference. Let us examine the difference between the two approaches.


This is what we want to achieve: Initialize an Employee variable (employeeInTarget) in the source task-flow and pass this variable as input to a target task-flow. This variable would be changed in the target task-flow and control would return to the source task-flow. We would examine the behaviour of the variables once this flow completes.

This is the Employee object:

Employee POJO


Here is the flow:
1. The default task-flow loaded on the page is source-flow.
2. SourceManager class is set as a page-flow bean for source-flow. This class has a private variable - employeeInSource - of type Employee.
3. source-flow calls target-flow and passes an instance of Employee as an input variable.
4. TargetManager class is set as a page-flow bean for source-flow. This class has a private variable - employeeInTarget - of type Employee.
5. When target-flow is called, the employeeInSource is copied (or referenced) into employeeInTarget.
6. target-flow has a return activity which changes the Employee variable (employeeInTarget) and returns to the source-flow.

source-flow

target-flow

"Pass by value"

When you select "Pass by value", a copy of the Employee variable is created and this copy is passed as input parameter to the target-flow task-flow. Each task-flow maintains a separate copy of the Employee variable.

Parameter settings for source-flow (pass by value)
 
Parameter settings for target-flow
Before returning to the source-flow, the Employee variable is changed.

TargetManager.java changes employee id to 101
But this change has no impact on the Employee variable of the SourceManager bean, as both of them maintain a separate copy of the class.

Employee variable in SourceManager.java is unchanged

"Pass by reference"

When you select "Pass by reference", (or rather, don't select pass by value) a reference of the Employee variable is passed as input parameter to the target-flow task-flow. Each task-flow now refers to the same copy of the Employee variable.

Parameter settings for source-flow (pass by reference)

Now when the target-flow changes the Employee variable, the same change is reflected on the variable on the source-flow as well.

Employee variable in SourceManager.java is now changed

Now depending on your use-case, you may select either of the 2 options. If you need each managed bean to maintain a separate copy of the managed variables, then you should pass by value. If your use-case needs the change done to a variable by one task-flow to be reflected onto the variable on the calling task-flow or on all task-flows in the chain, then go for pass by reference.

Cheers!




Comments