The other commonly used building blocks in ADF application are data controls and bindings. I assume, that readers are familiar with ADF facility of Bean Data Control: it is very easy to create one on any java class by doing Right-Click->Create Data Control on it.
This post shows a technique how to align a scope of java bean defined as manged bean in pageFlow Scope with an instance of the same bean exposed as bean data control.
The sample, available to download and run in JDeveloper R2, shows the technique and one particular usage scenario of it.
Short description of the sample application
An entry point to the sample is home.jsf. The page contains a bounded task flow sample-task-flow, embedded as a region. There are two view activities defined in the sample-task-flow: first and second. There is one method binding doSomethingUseful, which gets executed on transition between them:
Flow controller managed bean exposed as bean data control
One managed bean (Name: flowController, Scope: pageFlow) is defined in a sample-task-flow-definition.xml:
There is a property sampleValue and one method doSomethingUseful() in SampleFlowController.java:
The bean flowController is also exposed as (sparse) Bean Data Control:
Therefore , it can be used a declarative way and provides the same rapid design time experience ADF developers are likely familliar with.
The run time functionality provided by ADF Model, like currentRow and implementation of CollectionModel etc. is still available, so the combination of java and ADF enables to design highly modular service oriented view and controller layer and implement it using the strenghts of both approaches - declarative and java centric one.
The page first.jsff includes one element inputText bound to a sampleValue - created by D&D:
The bindings section of the page definition ,created implicitly by JDeveloper:
The method doSomethingUseful() was dragged&dropped on a flow diagram, so an appropriate pageDefinition file was also created implicitly, which looks like this:
We pick a value of bean attribute sampleValue in JDeveloper Expression Builder. The bean flowController is accessible in a section ADF Managed Beans:
Lets start the sample to have a look at behavior of it.
Running the sample
Once we start it (run home.jsf), ADF managed bean facility creates an instance of flowControler managed bean in a flow scope. We provide some value for the inputText element:
Click on Go to the next page and perform something useful - navigation case next to the second page is performed and a method doSomethingUseful() gets executed on a way to it.
The text on a second page is now converted to upperCase (it is aimed to show some useful functionality provided by the method):
We modify the text a little bit:
and press Go back to the first page. The result shows our modified value available on a first page:
It is supposed to show, that the scope of controller bean, defined as a managed bean in a page flow scope and exposed as bean data control is aligned.
The same instance of flowController bean is used, regardless of the way a bean is bound to some elements in a flow and pages of it.
Implementing flow scoped bean data control
To finish the post, i provide a complete source code (basically one line of code and one naming convention do the job) for the flow scoped data control used in a sample.
The implementation of SampleFlowDataControl.java:
And a generic implementation of base class FlowScopedDataControlBase.java for all flow scoped data controls:
The sample JDeveloper R2 workspace is provided at github.