我从素数面得到了这个,但我不想使用按钮并从bean调用确认对话框,我该如何做到这一点,或者渲染命令按钮并从bean执行?
问题是,我使用命令按钮来执行一个方法,这个方法中有一个if,当为true时,我想显示一个确认对话框。
<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>
您可以执行以下
<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();")
}