Get all the children components recursively for all UI Components

Problem- Need to reset all the input Components in the page on the click of a button.On first thought developer think of do this in the bean by getting the binding of the outermost layout component and then using the getChildren() method for that UIComponent.Then for all the UI components in the list,set the reset property to true.But problem here is that page contain multiple layout components. And getChildren() method would not recursively search for all the UI components (including inside the other layout components such as panelgrouplayout.


Implementation –
Its plain java.Call the method recursively.get each input Component and reset it.

// reset all the child uicomponents
private void resetValueInputItems(AdfFacesContext adfFacesContext,
                                 UIComponent component){
   List<UIComponent> items = component.getChildren();
   for ( UIComponent item : items ) {
      
       resetValueInputItems(adfFacesContext,item);
      
       if ( item instanceof RichInputText  ) {
           RichInputText input = (RichInputText)item;
           if ( !input.isDisabled() ) {
               input.resetValue() ;
               adfFacesContext.addPartialTarget(input);
           };
       } else if ( item instanceof RichInputDate ) {
           RichInputDate input = (RichInputDate)item;
           if ( !input.isDisabled() ) {
               input.resetValue() ;
               adfFacesContext.addPartialTarget(input);
           };
       }
   }
} 
 

Happy learning with Vinay Kumar in techartifact…

Re-order UI Componets using managed bean in Oracle ADF

Requirement – Re ordering of UI component using java code. Seems to be little tricky.

Solutions – Well , yes you can achieve that.For example, you are working on UI design in which you need to display two table inside panelGroupLayout.

PanelGroupLayout
Table 1
Table 2

Now you want on some condition , it should be like

PanelGroupLayout
Table 2
Table 1

public void yourCustomMethod() {

        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIViewRoot root = facesContext.getViewRoot();
        RichTable table1 = (RichTable)root.findComponent("table1");
        RichTable table2 = (RichTable)root.findComponent("table2");
        
        RichPanelGroupLayout pgl1 = (RichPanelGroupLayout)root.findComponent("pgl1");

        MoveChildComponentChange change = new MoveChildComponentChange(table2,pgl1,table1);
        change.changeComponent(pgl1);
        
        AdfFacesContext.getCurrentInstance().addPartialTarget(pgl1);
        
    }

For more understanding read this – http://docs.oracle.com/cd/E15051_01/apirefs.1111/e10684/oracle/adf/view/rich/change/MoveChildComponentChange.html

Author – Ankit Gupta

Happy Coding with Techartifact …..