Akhil Job
Akhil Job

Reputation: 419

Validation before firing a popup in adf Popup

I want o fire a popup before navigating to a new page fragment only if a certain data validation is positive(if a vo result returns more than zero rows).How would I add this validation that checks the vo results and display popup only if the validation turns out to be true.The popup should be displayed while clicking on a command link.If popup is shown no new navigation is done.In case validation returns false, we shiould navigate to a new page fragment instead of displaying popup .

Upvotes: 0

Views: 393

Answers (1)

Belal Awwad
Belal Awwad

Reputation: 315

Use the below code to show the popup programmatically

public static 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);
    }
}

Then add action listener to the link

 public void redirectAcion(ActionEvent actionEvent) {

 ViewObject yourViewObject= ADFUtils.getAm().getYourViewObject();

 long numOfRecords=yourViewObject.getEstimatedRowCount();
      if(numOfRecords==0)
       showPopup(myPopup,true);

    else{
     //redirect code .....
    }

  }

Upvotes: 1

Related Questions