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>adfBindings</filter-name> <filter-class>oracle.adf.model.servlet.ADFBindingFilter</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.
Viktoras,
I just ran across this article. Do you have any idea how I can get an Application Module from a traditional Servlet or Struts action class?
Thanks,
John
I haven’t used ADF quite a while, so I’m not sure, but I would think of something like this:
And make sure that ADFBindingFilter is mapped for your servlet.
I saw this a few weeks back and thought it would be very useful. I forgot to book mark it and spent about two hours this morning searching for this site again. So glad I found it. Thanks.
Excellent!!!
I was needed it badly.