如何显示来自bean的p:confirmDialog?

时间:2018-11-02 10:52:59

标签: jsf primefaces confirm-dialog

我是从primefaces那里得到的,但是我不想使用按钮并从Bean调用确认对话框,我该怎么做或渲染commandbutton并从Bean执行?

问题是Im使用命令按钮执行一个方法,当该方法为true时此方法中有一个if,那么我想显示一个确认对话框。      

<p:commandButton value="Destroy the World" actionListener="#{dialogView.destroyWorld}" update="message">
    <p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
</p:commandButton>

<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>

1 个答案:

答案 0 :(得分:-1)

您可以执行以下操作

 <p:commandButton value="Destroy the World" onclick="PF('confirmDialogwidget').show();">
 </p:commandButton>



<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" header="Are you sure?"
                     widgetVar="confirmDialogwidget">
    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" 
                     onclick="PF('confirmDialogwidget').hide();" />
</p:confirmDialog>

或也使用bean

<p:commandButton value="Destroy the World" actionListener="#{dialogView.destroyWorld}">
</p:commandButton>


<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" header="Are you sure?"
                 widgetVar="confirmDialogwidget">
    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" 
                     onclick="PF('confirmDialogwidget').hide();"/>
</p:confirmDialog>

在这里从Bean打开

 public void destroyWorld(){
    RequestContext.getCurrentInstance().execute("PF('confirmDialogwidget').show();")
}