【问题标题】:popup disappear even when validation failed即使验证失败,弹出窗口也会消失
【发布时间】: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


【解决方案1】:
  1. 取消按钮:
    oncomplete="customerDialogNew.show()" 更改为
    oncomplete="customerDialogNew.hide()"
  2. 保存按钮:
    删除ajax=false
    添加update="newCustomer"

所以你的按钮看起来像:

<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"/>               

支持豆:

 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()");
}

【讨论】:

    猜你喜欢
    • 2011-02-11
    • 1970-01-01
    • 2011-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多