2013-06-19 172 views
1

我曾經使用javascript確認框,並想切換到PrimeFaces <p:confirmDialog>如何通過`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>到確認對話框OK按鈕,但沒有工作過。這裏是對話框:

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

回答

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

是的,但'action'現在是從'commandLink'向下移動到'confirmDialog'。我如何將參數傳遞給對話框? – Danijel

+0

您可以更新確認對話框並從bean中檢索參數。在action方法中,將參數傳遞給bean,並在確認對話框中的bean的更新之後得到它。 – ovonel