gpt4 book ai didi

javascript - 访问托管 Bean 中的 ApplicationModule (FacesContext NULL)

转载 作者:行者123 更新时间:2023-12-03 10:30:40 25 4
gpt4 key购买 nike

我试图在托管 bean 类中获取应用程序模块,这样我就可以检索当前的 ViewObject 并更改它的属性。

我正在使用 DWR,因此我可以将 blob 图像作为参数从 JavaScript 传递到此类,这样我就可以将其保存在 ViewObject 属性上。

我的问题是我无法检索当前的 AppModuleImpl 因为FacesContext.getCurrentInstance(); 方法返回 null

我用来检索AppModule的方法:

在bean“FileUpload.java”上(由DWR使用)

// call VO
AppModuleImpl am = (AppModuleImpl)ADFUtil.resolvElDC("AppModuleDataControl");
ViewObjectImpl vo = am.getMyVO();

关于utils类“MyUtils.java”(通用函数类)

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();

关于javascript - 访问托管 Bean 中的 ApplicationModule (FacesContext NULL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29231782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com