我有一个带有表单的jsf页面,我需要通过一个受管bean(通过按钮)更新表单的属性(显然是当前的)。 所讨论的受管Bean已经存在并执行其他代码,即将文件上传到服务器并获取完整的文件路径(它返回一个字符串,例如file_name)。 我希望表单的属性(名为path的输入文本)在每次上传文件时都获得file_name值
答案 0 :(得分:0)
在Oracle ADF中可以通过多种方式以编程方式设置视图属性的值,这是其中两种:
/**
* 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");
转到组件>打开属性检查器>将绑定属性设置为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