I'm trying to get the Application Module in a managed bean class, so i can retrieve current ViewObject and change it's attributes.
I'm using DWR so i can pass a blob image as a parameter from JavaScript to this class, so i can save it on the ViewObject attribute.
My problem is that i can't retrieve the current AppModuleImpl because the FacesContext.getCurrentInstance();
method is returning null .
The methods i'm using to retrieve AppModule:
On bean "FileUpload.java" (used by DWR)
// call VO
AppModuleImpl am = (AppModuleImpl)ADFUtil.resolvElDC("AppModuleDataControl");
ViewObjectImpl vo = am.getMyVO();
On utils Class "MyUtils.java" (General functions class)
public static 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);
}
Any help on how to access current AppModule / ViewObject?
You can get the Application Module reference from the bean using:
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl"); //Name of application module in datacontrolBinding.cpx
But to get the ViewObject you can use:
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter = bc.findIteratorBinding("MyVOIterator");
ViewObject obj = iter.getViewObject();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.