Monday, August 19, 2019

Get object of ApplicationModule in managed bean


Requirment- Need an object of Application module in managed bean


Sometime we required to get an object of ApplicationModule in managed bean.May be we want to play with some VO object which we can get from
ApplicationModuleImpl Object only.
There are two ways.
First way-
FacesContext context = FacesContext.getCurrentInstance();
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc  = bindingContext.findDataControl("AppModuleAMDataControl"); // Name of application module in datacontrolBinding.cpx
AppModuleAMImpl appM = (AppModuleAMImpl)dc.getDataProvider();
Above AppModuleAMDataControl is name of application module in datacontrolBinding.cpx,open datacontrol and check the ID in tag. See below for reference.
<BC4JDataControl id="AppModuleAMDataControl" Package="oper.model.module"
                    FactoryClass="oracle.adf.model.bc4j.DataControlFactoryImpl" SupportsTransactions="true"
                    SupportsFindMode="true" SupportsRangesize="true" SupportsResetState="true"
                    SupportsSortCollection="true" Configuration="AppModuleAMLocalWeb" syncMode="Immediate"
                    xmlns="<a class="vglnk" href="http://xmlns.oracle.com/adfm/datacontrol"/" rel="nofollow"><span>http</span><span>://</span><span>xmlns</span><span>.</span><span>oracle</span><span>.</span><span>com</span><span>/</span><span>adfm</span><span>/</span><span>datacontrol</span><span>"/</span></a>>
Now you got the application module you can get the object of any ViewObjectImpl.
Second Way-
You can get the object of applicationModuleImpl by writing this line-
AppModuleAMImpl am = (AppModuleAMImpl)resolvElDC(AppModuleAMDataControl)
resolvElDC method is described below
private Object resolvElDC(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp =
            elFactory.createValueExpression(elContext, #{data. + data + .dataProvider}, Object.class);
        return valueExp.getValue(elContext);
    }

No comments:

Post a Comment