首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过托管bean填充属性?

如何通过托管bean填充属性?
EN

Stack Overflow用户
提问于 2019-06-20 20:34:47
回答 1查看 597关注 0票数 0

我有一个带有表单的jsf页面,我需要通过一个托管bean (通过一个按钮)更新表单的属性(显然是当前的)。有问题的托管bean已经存在,并执行其他代码,即将文件上传到服务器并获取完整的文件路径(它返回一个字符串,比如file_name)。我希望表单的属性(名为file_name的输入文本)在每次上传文件时获取path值

EN

回答 1

Stack Overflow用户

发布于 2019-07-03 14:01:07

在Oracle ADF中,有多种以编程方式设置视图属性值的方法,下面是其中两种:

使用极力推荐的JSFUtils.java库函数实现JSF的

  • 方式。

代码语言:javascript
运行
复制
/**
 * Method for setting a new object into a JSF managed bean
 * Note: will fail silently if the supplied object does
 * not match the type of the managed bean.
 * @param expression EL expression
 * @param newValue new value to set
 */
public static void setExpressionValue(String expression, Object newValue) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);

    //Check that the input newValue can be cast to the property type
    //expected by the managed bean.
    //If the managed Bean expects a primitive we rely on Auto-Unboxing
    Class bindClass = valueExp.getType(elContext);
    if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
        valueExp.setValue(elContext, newValue);
    }
}

JSFUtils.setExpressionValue("#{bindings.YOUR_VO_ATTRIBUTE.inputValue}","YOUR VALUE");

通过将jsf组件绑定到您的ADF Bean 来

转到您的组件>打开属性检查器>将绑定属性设置为您的Bean (将创建以下getter和setter)

代码语言:javascript
运行
复制
public void setMyInputText(RichInputText myInputText) {
    this.myInputText = myInputText;
}

public RichInputText getMyInputText() {
    return myInputText;
}

//then in your action you can just set and refresh component 
this.setMyInputText(YourValue);
AdfFacesContext.getCurrentInstance().addPartialTarget(this.getMyInputText);

https://gist.github.com/CedricL46/6cc291ce80601f50b66973e1000690a9

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56686123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档