我有一个带有表单的jsf页面,我需要通过一个托管bean (通过一个按钮)更新表单的属性(显然是当前的)。有问题的托管bean已经存在,并执行其他代码,即将文件上传到服务器并获取完整的文件路径(它返回一个字符串,比如file_name)。我希望表单的属性(名为file_name的输入文本)在每次上传文件时获取path值
发布于 2019-07-03 14:01:07
在Oracle ADF中,有多种以编程方式设置视图属性值的方法,下面是其中两种:
使用极力推荐的JSFUtils.java库函数实现JSF的
/**
* 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)
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
https://stackoverflow.com/questions/56686123
复制相似问题