我需要创建动态确认对话框。我有一个动态创建的CommandButton。因此,当按下时,将显示confirmDialog。我不知道如何在按下CommandButton时显示它。

最佳答案

您的按钮应如下所示:

<p:commandLink oncomplete="confirmation.show()"
  action="#{campagneComtroller.messageDeleteCam1(c)}"
  update=":frmDlgDel:confirmDialog">
  <p:graphicImage value="/image/delete.png" height="20" width="20"/>
</p:commandLink>


您的ConfirmDialog应该如下所示:

<h:form id="frmDlgDel">
            <p:confirmDialog id="confirmDialog"
                    message="#{campagneComtroller.messageDeleteCam1}"
                       header="#{bundles.messages['message.SupprimerGeneral']}" severity="alert" widgetVar="confirmation">
               <p:commandButton id="confirm" value="#{bundles.messages['message.OuiSure']}" oncomplete="confirmation.hide()" update=":formCam :frmDlgDel"
                        actionListener="#{campagneComtroller.deleteCam1()}" />
               <p:commandButton id="decline" value="NonPasEncore" onclick="confirmation.hide()" type="button" />
           </p:confirmDialog>
        </h:form>


您的Java代码应如下所示:

   public void messageDeleteCam1(Cam cam) {
conditionVerified = true; // ... you can put here your treatments
            if (conditionVerified) {
                messageDeleteCam1 = "this cam is bla bla bla ";
            } else {
                messageDeleteCam1 = "are you sure to delete this cam ?";
            }
        }


注意:我们在这里使用了oncomplete + update,这就是为什么我们可以在java处理后在confirmDialog中看到差异。

08-04 13:52