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

1 comment:

  1. Hi Mahmoud

    What if I want to add or remove a component based on some business logic, say a fetch from the db that when true gets reflected in the UI?
    Also can I do the above by overiding any methods in the viewrowimpl or any related classes so that it happens at runtime?
    thanks

    ReplyDelete

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...