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:
The page second.jsff doesn't contain a page definition. It is aimed to show, that the instance of flowController managed bean and its attributes can be used directly "JSF" way.
We pick a value of bean attribute sampleValue in JDeveloper Expression Builder. The bean flowController is accessible in a section ADF Managed Beans:
And a value expression of inputText element on a page looks like this:
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.
Helpful article. Thanks for share.
ReplyDeleteHi Donatas,
ReplyDeleteThanks for share.
However I tested your application it's working fine and
for unable understand the significance of FlowScopedDataControlBase.java and SampleFlowDataControl.java file.
Could you please why you create those two java file manually.
If the above two files not create then the sample functionality not work
Thanks in advance.
Hi Anonymous,
ReplyDeleteFlowScopedDataControlBase.java provides a functionality common to all flow scoped data controls.
SampleFlowDataControl.java inherits this functionality and provides a concrete type of a POJO to be exposed as a Data Control.
Very useful article! please clarify my below doubts
ReplyDeleteDoes this FlowScopedDataControl mean that the scope of the DataControl once the taskflow (or pageflow scope ends) is exited? which also implies all the objects which are created within this DC will be available for GC?
Hi Anonymous,
ReplyDeleteyes - in this usages scenario the FlowScopedDataControl itself doesn't contain a state itself but acts only as a "proxy" to a bean in a pageFlow scope, which is subject of a normal lifecycle of a taskflow.
The pojo instance of a ADF Bean Data Control, in this case SampleFlowDataControl, is managed internally by ADF - there is also a AM-Pooling involved behind the scenes (internalDCAMs - can by monitored in FMW).
In case of interest run the sample or your specific use case in Memory Profile in JDeveloper to get a complete picture of classes and objects involved and a memory consumption of them.
Regards, Donatas