Open p:confirmDialog on clicking of p:commandLink

2019-08-31 04:51发布

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.

1条回答
够拽才男人
2楼-- · 2019-08-31 05:22

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

查看更多
登录 后发表回答