【问题标题】:How to pass a parameter via `confirmDialog`?如何通过`confirmDialog`传递参数?
【发布时间】:2013-06-19 11:19:03
【问题描述】:

我以前使用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>

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

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

我也尝试将&lt;f:param&gt; 放入确认对话框的确定​​按钮中,但这也不起作用。这是对话框:

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

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    也可以通过action方法传递参数。

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

    【讨论】:

    • 是的,但是 action 现在从 commandLink 移动到 confirmDialog。我如何将参数也传递给对话框?
    • 您可以更新确认对话框并从 bean 中检索参数。在 action 方法中,您将参数传递给 bean,并在确认对话框中再次从 bean 更新后获取它。
    猜你喜欢
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多