如何通过`confirmDialog`传递参数?

时间:2013-06-19 11:19:04

标签: jsf jsf-2 primefaces

我以前使用javascript确认框,并希望切换到PrimeFaces <p:confirmDialog>

这就是现在的工作方式:

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

如果我使用deleteID,我如何传递confirmDialog参数? 这不起作用:

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

我也尝试将<f:param>放入确认对话框确定按钮,但这也不起作用。这是对话框:

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

1 个答案:

答案 0 :(得分:0)

您也可以通过操作方法传递参数。

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

确认对话框:

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