【发布时间】:2014-01-13 07:34:11
【问题描述】:
我正在使用 primefaces 3.5 和 jsf2。我有一个命令按钮,它显示一个对话框作为弹出窗口来注册新客户。各个领域都需要。当我提交缺少某些字段的表单时,弹出窗口会消失,好像什么也没发生一样。当我再次单击新按钮时,它会显示最后填写的带有错误消息的表单。 当验证失败时,我需要在我第一次提交时显示这个。 这是我的 html 代码的简短版本
<h:form id="mainForm">
<p:panel id="datatablePanel">
.........
<p:commandButton style="width: 8%;height: 100%" id="newButton" value="New" oncomplete="customerDialogNew.show()" icon="ui-icon-star"/>
</p:panel>
</:form>
<h:form id="newCustomerForm">
<p:panel id="customerPannel">
<p:dialog draggable="true" header="New Customer" widgetVar="customerDialogNew" id="dialog2">
<p:panelGrid id="newCustomer" columns="6" >
<p:outputLabel value="Name:" for="name" />
<p:inputText id="name" value="#{customerMB.name}" title="Name" required="true" requiredMessage="The Name field is required."/>
<p:message for="name" />
......
<p:commandButton style="height: 100%;width: 15%" value="Cancel" update="customerPannel" icon="ui-icon-arrowrefresh-1-n" process="@this" oncomplete="customerDialogNew.show()" />
<p:commandButton ajax="false" style="height: 100%;width: 15%" value="Save" icon="ui-icon-circle-check" styleClass="ui-priority-primary" actionListener="{customerMB.addCustomer()}"/>
</p:dialog>
</p:panel>
</h:form>
【问题讨论】:
-
查看上面的链接了解您的问题,它可能对您有所帮助。除此之外,与问题无关,我不明白您的
Cancel按钮的作用。按照process="@this"的顺序,我认为您应该使用immediate="true"并隐藏对话框而不是显示它。 -
我已经尝试了上面链接中建议的解决方案,但它对我不起作用。关于取消按钮:如果我在单击取消按钮时使用 immediate="true",则对话框会消失或重置填充的字段。
标签: jsf-2 primefaces dialog popup