im试图在删除用户之前通过按钮显示确认对话框,我从primefaces网站复制粘贴了示例,但不起作用,它只向我显示来自actionListener的消息。。。还尝试了在我的数据表之外使用自己的h:form的p:confirmDialog,但还没有成功,是因为我使用了模板客户端吗?任何想法都将不胜感激,这是我的代码:
<body>
<ui:composition template="./TemplateDefault.xhtml">
<ui:define name="content">
<h:outputStylesheet name="./css/modules.css" />
<p:dataTable var="user" value="#{user.getList()}">
<f:facet name="header">
USER LIST
</f:facet>
<p:column headerText="Id" style="width:5%">
<h:outputText value="#{user.id}" />
</p:column>
<p:column headerText="Name" style="width:20%">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Password" style="width:20%">
<h:outputText value="#{user.pwd}" />
</p:column>
<p:column headerText="Email" style="width:20%">
<h:outputText value="#{user.email}" />
</p:column>
<p:column headerText="Options" style="width:15%">
<h:form>
<p:growl id="message" showDetail="true" />
<p:commandButton actionListener="#{loginFormBean.msgDelete}" update="message" icon="ui-icon-trash" title="Delete User" >
<p:confirm header="Confirm" message="Are you sure?" icon="ui-icon-alert"/>
</p:commandButton>
<p:confirmDialog global="true">
<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>
</h:form>
</p:column>
<f:facet name="footer">
Found #{user.getList().size()} users.
</f:facet>
</p:dataTable>
</ui:define>
</ui:composition>
</body>
尝试将只包含p:confirmDialog的表单放在模板中h:body的后面。你可以在你的模板中做一些类似<ui:insert name="dialogs"/>
的事情,然后
<ui:define name="dialogs">
<h:form id="dialogForm">
<p:confirmDialog global="true">
<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>
</h:form>
</ui:define>
在您的代码中。
我尝试以下
<p:dataTable var="user" value="#{user.getList()}">
<f:facet name="header">
USER LIST
</f:facet>
<p:column headerText="Id" style="width:5%">
<h:outputText value="#{user.id}" />
</p:column>
<p:column headerText="Name" style="width:20%">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Password" style="width:20%">
<h:outputText value="#{user.pwd}" />
</p:column>
<p:column headerText="Email" style="width:20%">
<h:outputText value="#{user.email}" />
</p:column>
<p:column style="text-align: center" >
</p:column>
<p:column headerText="Options" style="width:15%">
<p:commandButton icon="ui-icon-trash" title="Delete User" onclick="PF('widgetVarDialog').show();" >
</p:commandButton>
</p:column>
<f:facet name="footer">
Found #{user.getList().size()} users.
</f:facet>
</p:dataTable>
<p:confirmDialog global="true" widgetVar="widgetVarDialog">
<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('widgetVarDialog').hide();" />
</p:confirmDialog>
你必须确保你得到的项目要删除