Danijel
Danijel

Reputation: 8604

How to pass a parameter via `confirmDialog`?

I used to use javascript confirmation box, and would like to switch to PrimeFaces <p:confirmDialog>.

This is how it works now:

<p:commandLink id="deleteFGLinkId"
  action="#FilterPresetGroupMgmtBean.delete}"
  onclick="if( !confirm('Preset Group will be removed. Are you sure you want to continue?') ){return false;}"
  onstart="bui.show();"
  oncomplete="bui.hide();"
  update=":pmForm:filterPresetTable :pmForm:messagePanel">
    <f:param value="#{item.value.ID}" name="deleteID"></f:param>
    <h:graphicImage alt="Delete Image" style="border: none" value="./images/x.png"/>
</p:commandLink>

How would I pass a deleteID parameter in case I use confirmDialog? This doesn't work:

<p:commandLink onclick="confirmPGDeletePopup.show()">
  <f:param value="#{item.value.ID}" name="deleteID"></f:param>
  <h:graphicImage alt="Delete Image" style="border: none" value="./images/x.png"/>
</p:commandLink>

I also tried putting <f:param> into confirmation dialog OK button, but that didn't work too. Here is the dialog:

<p:confirmDialog widgetVar="confirmPGDeletePopup" 
                     header="Confirm delete"
                     message="Preset Group will be removed. Are you sure you want to continue?"  
                     severity="alert">         
      <p:commandButton id="confirm" value="Yes" oncomplete="confirmPGDeletePopup.hide()" action="#{PresetGroupMgmtBean.delete}" update=":pmForm:presetPanel :pmForm:messagePanel"/>
      <p:commandButton id="decline" value="No" onclick="confirmPGDeletePopup.hide()" type="button" />                 
    </p:confirmDialog> 

Upvotes: 3

Views: 10246

Answers (1)

ovonel
ovonel

Reputation: 242

You can also pass the parameter through the action method.

<p:commandLink value="Some Magic" 
    action="#{bean.setSelectedItemId(yourItemId)}"
    ajax="true"
        update="yourConfirmationDialog"
    oncomplete="yourConfirmationDialogWidget.show();"/>

Confirmation dialog:

<p:outputPanel id="yourConfirmationDialog" layout="block">
      <p:confirmDialog widgetVar="yourConfirmationDialogWidget" 
                 header="Confirm delete"
                 message="Are you sure you want delete the item with #{bean.selectedItemId} ?"  
                 severity="alert">         
         <p:commandButton id="confirm" value="Yes" oncomplete="yourConfirmationDialogWidget.hide()" action="#{bean.delete}" />
         <p:commandButton id="decline" value="No" onclick="yourConfirmationDialogWidget.hide()" type="button" />                 
     </p:confirmDialog>  
</p:outputPanel>       

Upvotes: 2

Related Questions