即使验证失败,弹出窗口也会消失

时间:2013-12-25 09:48:20

标签: jsf-2 primefaces dialog popup

我正在使用primefaces 3.5和jsf2.I有一个命令Button,它显示一个对话框作为弹出窗口来注册新客户。各个领域都需要。当我提交缺少某些字段的表单时,弹出窗口就会消失,好像什么都没发生一样。当我再次点击按钮时,它会显示最后填写的表单并显示错误消息。 我需要在验证失败时第一次提交时显示。 这是我的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>

1 个答案:

答案 0 :(得分:0)

  1. 取消按钮:
               将oncomplete="customerDialogNew.show()"更改为
                      oncomplete="customerDialogNew.hide()"
  2. 保存按钮:
               删除ajax=false
               添加update="newCustomer"
  3. 所以你的按钮看起来像:

    <p:commandButton   style="height: 100%;width: 15%" value="Cancel" update="customerPannel" icon="ui-icon-arrowrefresh-1-n"  process="@this" oncomplete="customerDialogNew.hide()" />  
    <p:commandButton style="height: 100%;width: 15%" value="Save" icon="ui-icon-circle-check" styleClass="ui-priority-primary" actionListener="#{customerMB.addCustomer()}"  update="newCustomer"/>               
    

    支持Bean:

     public void addCustomer(){
        //do something
        System.out.println(name+"");
    
        //set name to null to prevent seeing old value when adding the second(or more) customer
        name=null;
        //Hide customerDialogNew if everything done.
        RequestContext.getCurrentInstance().execute("customerDialogNew.hide()");
    }