Open p:confirmDialog on clicking of p:commandLink

Tapas Bose picture Tapas Bose · Nov 15, 2012 · Viewed 17.3k times · Source

I am trying to open a PrimeFace ConfirmDialog on clicking of a PrimeFace CommandLink. But when the link is clicked the dialog is opened for a moment but vanishes instantly, I guess the page is being submitted. Here is the code:

<p:commandLink value="Delete" onclick="confirmation.show()"  />

<p:confirmDialog message="Are you sure, you want to delete ?"  header="Initiating deleting process"  widgetVar="confirmation">  
    <p:commandButton value="Yes Sure"  onclick="confirmation.hide()"  actionListener="#{adminCtrl.deleteUserById}" update="userData" >
        <f:attribute name="delete" value="#{user.userId}" />
    </p:commandButton>  
    <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   
</p:confirmDialog>

How can I make the dialog to stay opened by this way?

In the PrimeFace ShowCase the example deals with CommandButton and that was working but my requirement is to use CommandLink.

Is it possible? Any pointer would be very helpful to me.

Answer

Kerem Baydoğan picture Kerem Baydoğan · Nov 15, 2012

Use

<p:commandLink value="Delete" onclick="confirmation.show();return false;"  />

or

<p:commandLink value="Delete" onclick="confirmation.show()" type="button"/>

this way you can avoid a submit