Last active
July 3, 2019 12:02
-
-
Save CedricL46/6cc291ce80601f50b66973e1000690a9 to your computer and use it in GitHub Desktop.
See full tutorial here : https://cedricleruth.com/how-to-set-jsf-binding-attribute-programmatically-in-oracle-adf/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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