0

I can make a p:confirm for a button that has an action, but when it's an onclick instead of an action-attribute, then clicking "Yes" in the dialog does nothing. Any tips how to make this work?

This works:

            <p:commandButton action="#{customEditorBean.save}"
                value="Save" rendered="#{customEditorBean.canSaveContent}">
                <p:confirm message="Are you sure you want to save the content?" icon="ui-icon-alert" />
            </p:commandButton>

This doesn't work:

        <p:commandButton value="Close" onclick="PF('editorWidget').hide();">
            <p:confirm message="Do you want to close the editor without saving?" icon="ui-icon-alert" />
        </p:commandButton>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Steve Waters
  • 3,348
  • 9
  • 54
  • 94

2 Answers2

1

See something like this will work for you

<p:confirmDialog message="Are you sure about deleting this record?" 
                 widgetVar="deleteConfirm">
    <p:commandButton title="GDelYesButton" 
                     value="Yes" 
                     action="#{yourBean.delete}" 
                     oncomplete="PF('deleteConfirm').hide()" 
                     update=":growl"/>
    <p:commandButton title="GDelNoButton" 
                     value="No" 
                     oncomplete="PF('deleteConfirm').hide()"/>
</p:confirmDialog>

It should work we are using same thing in our application as well.

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • I'll try it later today. Thanks. – Steve Waters Jun 09 '16 at 06:36
  • It does work! would it be possible to hide the parent dialog too after clicking "yes"? :) Maybe this should be a separate question, but just wondering. Because my confirm dialog is appearing when clicking "Save" in a dialog window. Would be handy to close both the confirmDialog AND the dialog where the save-button is, at the same time. Cheers anyway! Marked your answer correct. – Steve Waters Jun 09 '16 at 11:34
  • 1
    Please check this http://stackoverflow.com/questions/18036122/primefaces-dialog-refer-to-parent something like this will help to close parent dialog as well. – Subodh Joshi Jun 10 '16 at 05:13
0

I use something similar for dialogue to remove an object, maybe you can interest this code

<h:form id="frmEliminar">
        <p:dialog header="Eliminar Caja #{cajaBean.caja.descripcion}" widgetVar="dlgEliminar" modal="true">                
            <h:outputText value="¿Desea eliminar?" />
            <p:commandButton value="Si" actionListener="#{cajaBean.eliminar()}" ajax="false" icon="b-ok" />
            <p:commandButton value="No" onclick="dlgEliminar.hide();" icon="b-cancel" />
        </p:dialog>
    </h:form>
John Lopez
  • 127
  • 1
  • 9