In Oracle ADF, sometimes you might want to use an ApplicationModule programmatically from a backing bean. You might need such behavior to create some AJAX functionality or just for your own convenience. It’s rather simple to accomplish, you just need to retrieve an ApplicationModule from the BindingContext.
The BindingContext is available during each web page request, you just have to use request-scoped attribute data.
The code sample below shows how to retrieve your SuperModule:
package electro.core;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import model.SuperModuleImpl;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
public class BeanWithApplicationModule {
public SuperModuleImpl getApplicationModule() {
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{data}");
BindingContext bc = (BindingContext) vb.getValue(context);
DCDataControl dc = bc.findDataControl("SuperModuleDataControl");
return (SuperModuleImpl) dc.getDataProvider();
}
...
}
The above code is pretty straight-forward:
- Get JSF FacesContext
- Create ValueBinding for EL expression #{data}
- Get value from binding evaluation and cast it to BindingContext
- Find data control by name (defined in DataBindings.cpx) from BindingContext
- Get your ApplicationModule implementation
Now you can use you ApplicationModule directly from backing bean (or even PhaseListener).
You must make sure, URL you are calling has an adfBindings filter. Filters by default are declared in WEB-INF/web.xml. We need ADFBindingFilter, which should already be there by default:
<filter>
<filter-name>adfFaces</filter-name>
<filter-class>oracle.adf.view.faces.webapp.AdfFacesFilter</filter-class>
</filter>
And we need to map this filter for our path, for example if its for some AJAX request to some-ajax-url:
<filter-mapping>
<filter-name>adfBindings</filter-name>
<url-pattern>some-ajax-url*</url-pattern>
</filter-mapping>
Or we can just add bindigs for Faces Servlet, so all requests will have bindings:
<filter-mapping>
<filter-name>adfBindings</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Helpful, thank you.