Wednesday 22 May 2013

How to show the pop-up by programmatically

Recently i was working one feature in ADF, where i wanted to show the pop-up programmatically.  I searched in the net but could'nt find the proper solution. So thought of posting this solution.


You can display the pop-up easily using <af:showPopupBehavior triggerType="action" popupId=":::p2"/>.
But in some situation if you want to do through Managed bean, follow the below procedure.

1. Add the popup component to your jsff (fragment page) with the dialog box in it, with the whatever message you want.


2. In the managed bean instantiate an Object of RichPopup with the setters and getters method, Below is the Managed bean code fragment for showing the Popup.

 public class ShowPopUp{
    private RichPopup richpopupId;
   
    public void setRichpopupId(RichPopup richpopupId) {
        this.richpopupId = richpopupId;
    }

    public RichPopup getRichpopupId() {
        return richpopupId;

  public void showPopup(){

  String popupId="p1";
  FacesContext context = FacesContext.getCurrentInstance();
  StringBuilder script = new StringBuilder();
  ExtendedRenderKitService extRenderKitSrvc = Service.getRenderKitService(context,            ExtendedRenderKitService.class);
  script.append("var popup = AdfPage.PAGE.findComponent('"+popupId+ "'); ").append("popup.show();");
  extRenderKitSrvc.addScript(context, script.toString());

}
}
 
In the above code String popupId="p1"; , p1 is the Id of the popup which you have added in 1st step.

3. Now go to the popup in the structure window of the jsff page, then go to the Advanced option in the Property inspector. In the Binding bind it to the "richpopupId" of the managed bean.



No comments:

Post a Comment