Many a times it is required to retrieve the ApplicationModule object from ADF managed beans, for example, to programmatically query a view object.
Invoke the below class like : AppModuleBean.getService(FacesContext.getCurrentInstance(), APP_MODULE_NAME))
This gives 3 different ways to retrieve the AppModule.
- Using BindingContext.
- Evaluating DataControl EL expression.
- Evaluating Bindings EL expression.
public static ApplicationModule getService(FacesContext fc, String name) {
DCDataControl dc = fromBindingContext(name);
if(dc == null) {
dc = fromEvaluatingDataControlEL(fc, name);
}
if(dc == null) {
dc = fromEvaluatingBindingsEL(fc, name);
}
return (ApplicationModule) dc.getDataProvider();
}
private static DCDataControl fromBindingContext(String name) {
DCDataControl dc = null;
BindingContext bindingContext = BindingContext.getCurrent();
if(bindingContext != null) {
dc = bindingContext.findDataControl(name + "DataControl");
}
return dc;
}
private static DCDataControl fromEvaluatingDataControlEL(FacesContext fc, String name) {
DCDataControl dc = null;
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{data." + name + "DataControl}", Object.class);
dc = (DCDataControl)valueExp.getValue(elContext);
return dc;
}
private static DCDataControl fromEvaluatingBindingsEL(FacesContext fc, String name) {
DCDataControl dc = null;
DCBindingContainer bc = (DCBindingContainer)fc.getApplication().evaluateExpressionGet(fc, "#{bindings}", BindingContainer.class);
if(bc != null) {
dc = bc.findDataControl(name + "DataControl");
}
return dc;
}
}
Comments
Post a Comment