0

I am working with primefaces 3.5 and jsf2.I have a command Button that shows up a dialog as a popup to register a new customer. All fields are required. when i submit the form with missing some fields the popup disappears as if nothing happened. And when i click again on the button new it shows up the last filled form with error messages. I need this to be shown first time i submit when validation is failed. Here is a short version of my html code

<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>
junior developper
  • 448
  • 2
  • 19
  • 40
  • possible duplicate of [Keep p:dialog up when a validation error occurs after submit](http://stackoverflow.com/questions/9195756/keep-pdialog-up-when-a-validation-error-occurs-after-submit) – Aritz Dec 25 '13 at 13:04
  • See the link above for your question, it may be helpful for you. Apart from that and unrelated to the problem, I don't understand what your `Cancel` button does. In order of a `process="@this"` you should use an `immediate="true"` and hide the dialog instead of showing it I think. – Aritz Dec 25 '13 at 13:07
  • I already tried the solution suggested in the above link but it didn't work for me. about the cancel button: if i use immediate="true" when i click on the cancel button the dialog disappear instead or resetting the fields filled. – junior developper Dec 25 '13 at 14:16

1 Answers1

0
  1. Cancel Button:
    Change oncomplete="customerDialogNew.show()" to
    oncomplete="customerDialogNew.hide()".
  2. Save Button:
    Remove ajax=false.
    Add update="newCustomer".

So your Buttons looks like:

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

Backing 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()");
}
nosnhoj
  • 793
  • 1
  • 12
  • 30