访问托管 Bean 中的 ApplicationModule (FacesContext NULL)
Access ApplicationModule in Managed Bean (FacesContext NULL)
我正在尝试在托管 bean 中获取应用程序模块 class,这样我就可以检索当前的 ViewObject 并更改它的属性。
我正在使用 DWR,因此我可以将 blob 图像作为参数从 JavaScript 传递到此 class,因此我可以将其保存在 ViewObject 属性中。
我的问题是我无法检索当前的 AppModuleImpl,因为
FacesContext.getCurrentInstance();
方法返回 null.
我用来检索 AppModule 的方法:
在 bean "FileUpload.java" 上(由 DWR 使用)
// call VO
AppModuleImpl am = (AppModuleImpl)ADFUtil.resolvElDC("AppModuleDataControl");
ViewObjectImpl vo = am.getMyVO();
关于实用程序 Class "MyUtils.java"(一般功能 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);
}
关于如何访问当前 AppModule / ViewObject 的任何帮助?
您可以使用以下方法从 bean 中获取应用程序模块引用:
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl"); //Name of application module in datacontrolBinding.cpx
但要获取 ViewObject,您可以使用:
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter = bc.findIteratorBinding("MyVOIterator");
ViewObject obj = iter.getViewObject();
我正在尝试在托管 bean 中获取应用程序模块 class,这样我就可以检索当前的 ViewObject 并更改它的属性。
我正在使用 DWR,因此我可以将 blob 图像作为参数从 JavaScript 传递到此 class,因此我可以将其保存在 ViewObject 属性中。
我的问题是我无法检索当前的 AppModuleImpl,因为
FacesContext.getCurrentInstance();
方法返回 null.
我用来检索 AppModule 的方法:
在 bean "FileUpload.java" 上(由 DWR 使用)
// call VO
AppModuleImpl am = (AppModuleImpl)ADFUtil.resolvElDC("AppModuleDataControl");
ViewObjectImpl vo = am.getMyVO();
关于实用程序 Class "MyUtils.java"(一般功能 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);
}
关于如何访问当前 AppModule / ViewObject 的任何帮助?
您可以使用以下方法从 bean 中获取应用程序模块引用:
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl"); //Name of application module in datacontrolBinding.cpx
但要获取 ViewObject,您可以使用:
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter = bc.findIteratorBinding("MyVOIterator");
ViewObject obj = iter.getViewObject();