Thursday, November 25, 2010

How to invoke popup component programmatically in ADF

Hi All,
     Here is a sample solution for invoking the popup component from a method in the managed bean.

Solution.
     1.Create a button in the Jspx page.
     2.Create a popup componet inside the af|form (for eg:popup id=p1)   and bind the popup to a managed bean with name popup
     3.In the Action property of button,invoke a method in the managed bean( for eg.the method caller() )

In the backing bean code,

  public String caller(){
      showPopup(popup, null);
      return null;
 }
 public static void showPopup(RichPopup popup, UIComponent component) {
      FacesContext context = FacesContext.getCurrentInstance();
      String alignId = (component==null) ? null : component.getClientId(context);
      StringBuilder script = new StringBuilder();
      script.append("var popup = AdfPage.PAGE.findComponent('").append("p1").append("'); ")
              .append("if (!popup.isPopupVisible()) { ")
              .append("var hints = {}; ");
       if (alignId!=null) {
         script.append("hints[AdfRichPopup.HINT_ALIGN_ID] = '").append(alignId).append("'; ")
           .append("hints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_AFTER_START; ");
       }
        script.append("popup.show(hints);}");
        ExtendedRenderKitService erks =
          Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
       }
    
Hi, Onething note this works in JDeveloper 11.1.1.2.0  But I dont know how about in other version.I hope it will work in all versions,

         If it dosn't works post your comment or mail to : felixandrew3@gmail.com . I will send you the sample code.

1 comment:

  1. In 11.1.1.3 you can bind the popup to a backing bean, and invoke it by calling

    RichPopup.PopupHints hints = ......;
    p1.show(hints);
    // or
    p1.hide();

    ReplyDelete