08 March, 2012

Add UI Components at Runtime In ADF

Sometimes we need to add UI components to page at run-time.
So I developed generic method that we can use it for adding components to page at run-time

Method Code 

    public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent){
        parentUIComponent.getChildren().add(childUIComponent);
        AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
    }


Call Method From Anywhere

    public void addUI(ActionEvent actionEvent) {
        // Add event code here...
        RichInputText ui = new RichInputText();
        ui.setId("rit1");
        ui.setLabel("Label of RichInputText");
        ui.setValue("Value of RichInputText");
        
        addComponent(getPgl1(), ui);
    } 

Note that getPgl1() return component of PanelGroupLayout component
I created ui object of RichInputText, You can create object of any UIComponents subclass like RichInputDate, RichSelectOneChoice, RichDecorativeBox, ...............

Mahmoud Ahmed El-Sayed
Recommended Post Slide Out For Blogger