Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricL46/6cc291ce80601f50b66973e1000690a9 to your computer and use it in GitHub Desktop.
Save CedricL46/6cc291ce80601f50b66973e1000690a9 to your computer and use it in GitHub Desktop.
//There is multiple way to programmatically set a value of a view attribute in Oracle ADF :
// 1. The JSF way using the highly recommended JSFUtils.java library function :
/**
* 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");
// 2. By binding the jsf component to your ADF Bean
//Go To your component > Open property inspector > Set Binding Attribute to your Bean (will create the following getter and 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment