Tuesday 2 August 2011

JDeveloper 11.1.2.0 : Looking up a binding reference to inherited/referenced Application Module as Data Provider via the Data Control binding

The whole idea of getting an Application Module reference, programmatically, via the bindings by using the appropriate Data Control name is common practice in ADF. As we all know you do it like this:
DCBindingContainer dcBindingContainer = (DCBindingContainer) getBindingContainer();
DCDataControl dataControl = dcBindingContainer.findDataControl("DataControlName");
ApplicationModule appMod = (ApplicationModule) dataControl.getDataProvider();
// (where 'ApplicationModule' will be a specific ApplicationModule class of yours; i.e. 'CommonAM')
However, if you are trying to find a reference to a referenced/inherited Application Module via its Data Control before you've ever used any bindings on this Data Control, the programmatic approach will return a null reference.
The solution is to drag and drop any sub-element from the given Data Control onto a page of yours and that will ensure that the needed BC4J configuration for the use of the Data Control will be added to the file: "DataBindings.cpx" (of course you can delete the created component on your page afterwards)

Here's an example BC4J config:
<BC4JDataControl id="CommonAMDataControl" Package="com.common.model.am"
                     FactoryClass="oracle.adf.model.bc4j.DataControlFactoryImpl" SupportsTransactions="true"
                     SupportsFindMode="true" SupportsRangesize="true" SupportsResetState="true"
                     SupportsSortCollection="true" Configuration="CommonAMLocal" syncMode="Immediate"
                     xmlns="http://xmlns.oracle.com/adfm/datacontrol"/>


Once this BC4J configuration has been added...your java code will lookup the bindings successfully. 

No comments:

Post a Comment