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
Call Method From Anywhere
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
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
Hi Mahmoud
ReplyDeleteWhat 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