Wednesday, October 8, 2008

Important code samples commonly used in ADF

In this post I am listing up important code samples commonly used in ADF .

Code to access the application module methods from the managed bean

To make sure that your application module method is accessible from the view layer, in the application module editor, do shift the method from “Avaliable” to “Selected List” under the client interface option.

FacesContext fc = FacesContext.getCurrentInstance();
ValueBinding vb = fc.getApplication().createValueBinding("#{data}");
BindingContext bc = (BindingContext)vb.getValue(fc);
DCDataControl dc = bc.findDataControl("HRAppModuleDataControl");
ApplicationModule am = (ApplicationModule)dc.getDataProvider();
HRAppModule hrAm = (HRAppModule)am;

In the above example HRAppModuleDataControl is the Data control used in your application.You can find the exact name used in your application in the DataBindings.cpx file inside the .HRAppModule is the Application module client interface class. And setCurrentEmpRow is the method inside the Applicatin module which is need to be called.

Code to access the page bindings from the Managed bean

DCBindingContainer bc1 = this.getBindings();
String empId1 = bc1.findIteratorBinding("EmpDeptTableIterator").

In the above example EmpDeptTableIterator is the iterator name from which I want to access the EmployeeId.

In the above example getBinding() refers to the method which returns the object of type DCBindingContainer. If its not already there, add the following code snippet to your same managed bean.

private DCBindingContainer bindings;
public DCBindingContainer getBindings()
{ return bindings;
public void setBindings(DCBindingContainer bindings)
{ this.bindings = bindings; }

An inside your faces-config.xml add the following managed property inside your managed bean.


Anonymous said...

hi vikram,
while trying to access page bindings from the managed bean, the "bindings" is null and throwing null pointer exception.

I have add managed property in the faces-config.xml properly..

am i missing something?


Vikram Kohli said...

Hi Srini,

Above code is for ADF 10g.If you are using ADF11g, then u have to change the code.