Sunday, March 16, 2014

How to programatically invoke a button on ADF Form ?

This blog explains about how to invoke a button in a backing bean programatically based on some condition ?

       
        import javax.faces.event.ActionEvent;
        import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
 // Get the commandButton component based on command button ID
        RichCommandButton button = (RichCommandButton) JSFUtils.findComponent("backBtn");
        ActionEvent actionEventBut = new ActionEvent(button);
  // Add it to actionEvent queue
        actionEventBut.queue();
  // Below is the logic to get the root component
  FacesContext facesContext = FacesContext.getCurrentInstance();
  if (facesContext != null) {
            UIComponent root = facesContext.getViewRoot();
            component = findComponent(root, pComponentId);
        }
  private static UIComponent findComponent(UIComponent pRoot,
                                             String pComponentId) {
        if (pComponentId.equals(pRoot.getId()))
            return pRoot;

        UIComponent kid = null;
        UIComponent result = null;
        Iterator kids = pRoot.getFacetsAndChildren();
        while (kids.hasNext() && (result == null)) {
            kid = (UIComponent)kids.next();
            if (pComponentId.equals(kid.getId())) {
                result = kid;
                break;
            }
            result = findComponent(kid, pComponentId);
            if (result != null) {
                break;
            }
        }
        return result;
    }
  
       
 

No comments:

Post a Comment