Search code examples
jsfprimefacesconfirmation

How to make confirmation dialog for onclick="PF('dialogWidget').hide();


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>

Solution

  • 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.