Set EL expression in value (properties) of programmatically created ADF Faces component

Sharing is Caring
When we are working with ADF Faces components programmatically then we create, set styles,set value of that component from the managed bean.
This post is about how to set EL expression as a component’s value that will be resolved at run time and return the desired value

Suppose i am creating an af:inputText and i want that it’s value should be derived from an attribute that is present in page bindings. I have EmployeeId added in  binding section of pagedef, to get it’s value through EL i have to use this expression- #{bindings.EmployeeId.inputValue}
Now i have to set this expression as value of programmatically created inputText

See this simple peace of code –

    /**Method to resolve a String to ValueExpression
     * @param data
     * @return
     */
    public ValueExpression getValueExpression(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
        return valueExp;

}

/**Method to add dynamically created component to a parent layout
* @param parentUIComponent
* @param childUIComponent
*/
public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
parentUIComponent.getChildren().add(childUIComponent);
AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
}

/**Method to create inputText programmatically and sets expression as it’s value
* @param actionEvent
*/
public void createComp(ActionEvent actionEvent) {
RichInputText ui = new RichInputText();

//Resolve string to value expression
ui.setValueExpression(“value”, getValueExpression(“#{bindings.EmployeeId.inputValue}”));

ui.setId(“pit1”);
ui.setContentStyle(“width:200px;color:navy”);

//getParentGroupLayoutBind is the component binding of parent panel group layout
addComponent(getParentGroupLayoutBind(), ui);
}

Cheers:) Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Set EL expression in value (properties) of programmatically created ADF Faces component”

  1. Hi!
    thank your code.
    but when I apply your code with richtextEdittor is error can you help me with richEdittor
    my code here:
    RichTextEditor ui = new RichTextEditor();

    ui.setId("ID"));

    ui.setContentStyle("font-weight:bold;color:red");

    ui.addValidator(Fn_validator("#{bean_control.getObject}"));
    ui.setValueExpression("binding", Fn_binding("#{bean_control.RTEValue"));
    addComponent(getPFL(), ui);
    Fn_binding here:
    public static ValueExpression Fn_binding(String binding_name){

    FacesContext fc = FacesContext.getCurrentInstance();
    Application app = fc.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = fc.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, binding_name, Object.class);
    return valueExp;

    }
    can you help me how to get object value of RichTextEditor
    thank a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *