Thursday 21 February 2013

ADF: Code to use popup

## Code to use popup

Note: For using this code, first you have to make binding of the popup which is displayed on your webpage.
And here in the code I have variable pop to bind the popup.



1)showPopup method to call popup
private void showPopup(RichPopup pop, boolean visible) {  
    try {  
      FacesContext context = FacesContext.getCurrentInstance();  
      if (context != null && pop != null) {  
        String popupId = pop.getClientId(context);  
        if (popupId != null) {  
          StringBuilder script = new StringBuilder();  
          script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");  
          if (visible) {  
            script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");  
          } else {  
            script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");  
          }  
          ExtendedRenderKitService erks =  
            Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);  
          erks.addScript(context, script.toString());  
        }  
      }  
    } catch (Exception e) {  
      throw new RuntimeException(e);  
    }  
  }

2)And import these packages

import org.apache.myfaces.trinidad.event.SelectionEvent;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
import javax.faces.context.FacesContext;

3)Use to show or hide popup in the page
private RichPopup pop;
showPopup(pop, true);

** incase you want to hide the popup, use

showPopup(pop, false);

1 comment:

  1. Hi.. I am beginner to ADF and I didn't find any good resource to learn how ADF application should be coded.. can you please share some code resources to get clear idea about application development in ADF..

    ReplyDelete