Tuesday, February 21, 2012

How To Fix Data Control Initialization Error with ADF Libraries

If you are getting NullPointer exception from Data Control bindings, when integrating ADF Libraries into one single application, most likely Data Control method is accessed bypassing ADF Model layer. I have described this problem and solution back in 2009 - Integration in Oracle ADF Through ADF Libraries and ADF Task Flows. Long story short - NullPointer exception may happen when referencing Data Control directly, and when Data Control was not initialized yet. However, sometimes based on a use case - we need to call Data Control directly, for example from Task Flow initialization method (where we don't have access to Page Definition). This post will describe quite simple trick how to bypass Data Control initialization problem.

Download updated sample application - ADFIntegration_v2.zip.

Just to refresh your memory about original problem described in the blog post above. If there is Method Call activity in the Task Flow and this Method Call invokes Java method directly with access to Data Control:

You may get NullPointer exception, after such Task Flow will be integrated into main application. Keep in mind - Task Flow will work fine when testing it locally. Exception stack trace in my case:

Exception happens because we are calling getApplicationModuleForDataControl('...') method, it fails to locate Data Control entry in multi ADF library environment:

In case we still need to call getApplicationModuleForDataControl('...') method from specific Java method, before Data Control gets initialized - we can trick it by calling empty method through ADF Bindings just before the Java initialization method. Declare empty method in AM Implementation class and expose it through client interface:

Once this empty method is exposed and available in Data Control:

Invoke it through Method Call with ADF Bindings - just before the Java initialization Method Call:

This will ensure proper Data Control initialization for current Task Flow and getApplicationModuleForDataControl('...') method will be able to locate Data Control entry.

When running sample application, from main screen press First Remote button:

Task Flow is loading correctly, Data Control was located successfully from Java initialization method:


Frank Nimphius said...

You don't need to invoke a method. Having a PageDef file alone is sufficient for the Binding cOntext to be created

Andrej Baranovskij said...

I guess so, its just more convenient to create Method Call with Page Def by referencing AM method. Also it adds more visibility from maintenance point of view, because we can check what AM we are initializing (if there are several). But okej, it all depends on requirement - sometimes may be its better just to map empty Page Def.


Andrej Baranovskij said...

As per Frank comment, I have tested empty PageDef approach and posted sample application - http://andrejusb.blogspot.com/2012/02/update-how-to-fix-data-control.html