Thursday, September 15, 2011

Programmatic ADF Task Flow Router

Blog reader is asking how to control ADF Task Flow navigation programmatically (JDeveloper 11g and ADF Task Flow Parameters), in order to minimize predefined static outcomes inside ADF Task Flow diagram. I would go with simplest option and use Router activity available for ADF Task Flows. However, depending on use case, we may require to implement routing logic inside custom Java method.

Sample application - ADFConditionalNavigation.zip, explains how to implement programmatic ADF Task Flow router inside Java bean class. This sample is implemented using latest JDeveloper 11g R2, but same logic can be applied with previous JDeveloper 11g versions as well.

For the test case, I have defined three buttons, each assigned with af:setPropertyListener:


Each button points to the same navigation outcome called route:


This is the reason, why we are using af:setPropertyListener, to distinguish navigation outcome dynamically. Navigation outcome name for each of the buttons is stored inside our custom bean from View scope:


There is a bug in JDeveloper 11g R2 IDE, it can't resolve managed bean methods or properties declared in any scope except session or request (see 'To' part highlighted in red). Good thing this is only IDE bug, on runtime it works well. Our managed bean is declared in view scope, to make sure stored outcome name will be available for programmatic routing:


Navigation from main page is always performed only through route outcome. Next we are hitting Method Call - it calls our custom method from managed bean. This custom method evaluates current dynamic outcome name and returns real outcome (which will be jobs or empls in our case):


If we look into Method Call properties, we will see custom method name with routing logic (IDE bug makes it look red, same as explained above). Instead of using Fixed Outcome, toString() = true option is specified. This means instead of using predefined outcome name, ADF will use return value of our custom method as navigation outcome:


Let's look into custom router method code. Nothing complex - we are checking value of dynamic outcome initialized from af:setPropertyListener and based on defined condition returning first or second real outcomes. First two buttons are navigating to empls, third button navigates to jobs:


No comments: