I would like to call confirmDialog
via backing. This code works perfectly, but how can I set the message and set the actionlistener of the confirmDialog via backing? There is two condition, while:
How to do that? 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 Backing:
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();");
}
}
If I understood your question correctly.. I would do it in this way.
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();");
}
}
Basically you add a hidden button (with p:confirm) in the usual way and you click it through jQuery.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With