Steve Waters
Steve Waters

Reputation: 3548

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>

Upvotes: 0

Views: 5226

Answers (2)

John Lopez
John Lopez

Reputation: 127

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>

Upvotes: 0

Subodh Joshi
Subodh Joshi

Reputation: 13482

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.

Upvotes: 1

Related Questions