Surface calls ConfirmDialog from backup

I would like to call confirmDialogusing support. This code works fine, but how can I set the message and install the confirmDialog actionlistener with support? There are two conditions:

  • The user checks option A on the checkbox (I missed the code), then he must directly print the text for the console. โ†’ This is done using the code below
  • The user checks option B on the checkbox, then he should show the Dialog confirmation, and while the user presses the YES button, he should call another function based on.

How to do it? Thanks.

<p:commandButton value="Execute" icon="ui-icon-circle-check"  update="frmContent" actionListener="#{backing.validate}" />

<p:confirmDialog id="cfmDlg" widgetVar="wvCfmDlg" global="true" >
    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>

In backup:

public void validate() {
    if(mode.equals("1")) {
        System.out.println("OK");
    } else {
        //call confirmDialog and set message + action listener
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("wvCfmDlg.show();");
    }
}
+4
source share
1 answer

. .

XHTML

<p:commandButton style="display: none" 
                 widgetVar="confirmButton"  
                 actionListener="#{backing.yesFunction}" >
   <p:confirm header="Confirmation" message="Are you sure?" /> 
</p:commandButton>

<p:commandButton value="Execute"
                 actionListener="#{backing.validate}" /> 

<p:confirmDialog id="cfmDlg" global="true" >
      <p:commandButton value="Yes" />
      <p:commandButton value="No" />
</p:confirmDialog>

bean

public void validate() {
   if(mode.equals("1")) {
       System.out.println("OK");
   } else {
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('confirmButton').jq.click();");
   }
}

( p: ) , jQuery.

+10

Source: https://habr.com/ru/post/1527278/


All Articles