ADFUtils Class: Best for Accessing Components in from the Managed Bean

import java.util.Iterator;
import java.util.Map;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

import oracle.adf.model.BindingContext;
import oracle.adf.model.DataControlFrame;
import oracle.adf.view.rich.context.AdfFacesContext;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;


public class ADFUtils {
    private ADFUtils() {
    }

    /**
     * This method returns any UI component whose id is passed.
     * @param id the id of the component
     * @return the UIComponent
     */
    public static UIComponent getUIComponent(String id) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
            UIViewRoot viewRoot = facesContext.getViewRoot();
            if (viewRoot != null) {
                return viewRoot.findComponent(id);
            }
        }
        return null;
    }


    /**
     * Refreshes the page/viewRoot.
     * @return the viewId of the current page
     */
    public static String refreshViewRoot() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        String viewId = facesContext.getViewRoot().getViewId();
        ViewHandler viewHandler =
            facesContext.getApplication().getViewHandler();
        UIViewRoot viewroot = viewHandler.createView(facesContext, viewId);
        viewroot.setViewId(viewId);
        facesContext.setViewRoot(viewroot);
        return viewId;
    }

    /**
     * Invokes the specified function with the specified params.
     * @param functionName the name of the js function
     * @param params the params to be passed
     */
    public static void runJsFunction(String functionName, String params) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExtendedRenderKitService extRenderKitSvc =
            Service.getRenderKitService(facesContext,
                                        ExtendedRenderKitService.class);
        extRenderKitSvc.addScript(facesContext,
                                  functionName + "('" + params + "');");
    }

    /**
     * Invokes the specified function with the specified params.
     * @param functionName the name of the js function
     */
    public static void runJsFunction(String functionName) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExtendedRenderKitService extRenderKitSvc =
            Service.getRenderKitService(facesContext,
                                        ExtendedRenderKitService.class);
        extRenderKitSvc.addScript(facesContext, functionName + "();");
    }

    // Get the Component based on given UIComponent ID and refresh the component

    public static void refreshComponent(String pComponentID) {
        UIComponent component = findComponentInRoot(pComponentID);
        refreshComponent(component);
    }


    // Get Faces Context, Get Root Component, Find the given Component From the root component

    public static UIComponent findComponentInRoot(String pComponentID) {
        UIComponent component = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
            UIComponent root = facesContext.getViewRoot();
            component = findComponent(root, pComponentID);
        }
        return component;
    }


    // Refresh the Component

    public static void refreshComponent(UIComponent component) {
        if (component != null) {
            AdfFacesContext.getCurrentInstance().addPartialTarget(component);
        }
    }

    // Get the specific  component from a root component tree.

    public static UIComponent findComponent(UIComponent root, String id) {
        if (id.equals(root.getId()))
            return root;

        UIComponent children = null;
        UIComponent result = null;
        Iterator childrens = root.getFacetsAndChildren();
        while (childrens.hasNext() && (result == null)) {
            children = (UIComponent)childrens.next();
            if (id.equals(children.getId())) {
                result = children;
                break;
            }
            result = findComponent(children, id);
            if (result != null) {
                break;
            }
        }
        return result;
    }
  
    /**
     * Programmatic evaluation of EL.
     *
     * @param el EL to evaluate
     * @return Result of the evaluation
     */
    public static Object evaluateEL(String el) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
            facesContext.getApplication().getExpressionFactory();
        ValueExpression exp =
            expressionFactory.createValueExpression(elContext, el,
                                                    Object.class);

        return exp.getValue(elContext);
    }

    /**
     * Programmatic invocation of a method that an EL evaluates to.
     * The method must not take any parameters.
     *
     * @param el EL of the method to invoke
     * @return Object that the method returns
     */
    public static Object invokeEL(String el) {
        return invokeEL(el, new Class[0], new Object[0]);
    }

    /**
     * Programmatic invocation of a method that an EL evaluates to.
     *
     * @param el EL of the method to invoke
     * @param paramTypes Array of Class defining the types of the parameters
     * @param params Array of Object defining the values of the parametrs
     * @return Object that the method returns
     */
    public static Object invokeEL(String el, Class[] paramTypes,
                                  Object[] params) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
            facesContext.getApplication().getExpressionFactory();
        MethodExpression exp =
            expressionFactory.createMethodExpression(elContext, el,
                                                     Object.class, paramTypes);

        return exp.invoke(elContext, params);
    }

    /**
     * Sets a value into an EL object. Provides similar functionality to
     * the  tag, except the from is
     * not an EL. You can get similar behavior by using the following...

     * setEL(to, evaluateEL(from))
     *
     * @param el EL object to assign a value
     * @param val Value to assign
     */
    public static void setEL(String el, Object val) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
            facesContext.getApplication().getExpressionFactory();
        ValueExpression exp =
            expressionFactory.createValueExpression(elContext, el,
                                                    Object.class);

        exp.setValue(elContext, val);
    }
}

Source: Forum

Alternate Link:Alternate, includes Application Module and Binding Utils as well

How to show Popup programmatically in Oracle ADF

When trying to open a Popup on JSF/JSFF page programmatically through Managed Bean, use the following method and pass the ID of the popup to the method:

 public void openPopup(String popupId) {
         ExtendedRenderKitService erkService =
         Service.getService(FacesContext.getCurrentInstance().getRenderKit(),
         ExtendedRenderKitService.class);
         erkService.addScript(FacesContext.getCurrentInstance(),
         "var hints = {autodismissNever:true}; " +
         "AdfPage.PAGE.findComponent('" + popupId +
         "').show(hints);");
 }
OR

On the button , write a method on the action event.
 public void ShowPopup(ActionEvent actionEvent) {
          RichPopup.PopupHints hints = new RichPopup.PopupHints();
          this.getPopUp().show(hints);
 
 }

If you want to hide the popup..you can write like this

  public void HidePopup(ActionEvent actionEvent) {
           RichPopup.PopupHints hints = new RichPopup.PopupHints();
           this.getPopUp().hide();
 
  }

General use is when you wish to call the a popup from a button press but first want to execute some actions/processings in the screen on the button click.

In the button on the JSFF, just add a actionListener and then call the openPopup() method from the action listener or any other method you wish to.

Source: Forum