2 Replies Latest reply on Sep 10, 2008 8:18 AM by tupdev

    ModalPanel and Validation Problem

    tupdev

      Hi,

      i've the following problem.

      i've a modalpanel with two requiered textfields to edit the input. on my mainpage there is an a4j-commandbutton to set the value of these two fields and to display the modalpanel. if i filled both fields and click the save button it works fine. but if i left one field blank, edit only the other one and click the save button the message "requierd fields..." is displayed and the modalpanel didn't close. thats correct. But it seams that the edited value has been saved. if i close the modalpanel and open it again, only the blank field is filled with the right value, the value of the other field is still the edited value and not the init value.why?what can i do that this example works?

      testpage.xhtml

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
       <head>
       <script type="text/javascript">
       function ajaxRequestContainsErrors() {
       return document.getElementById("maximumSeverity").value == "2";
       }
      
       function closeModalPanel(panelId) {
       if (!ajaxRequestContainsErrors()) Richfaces.hideModalPanel(panelId);
       }
       </script>
       </head>
      
       <body>
       <a4j:outputPanel ajaxRendered="true" id="mainErrorPanel">
       <h:form style="display:none" prependId="false">
       <h:inputHidden id="maximumSeverity" value="#{facesContext.maximumSeverity.ordinal}"/>
       </h:form>
       </a4j:outputPanel>
       <h:form id="account">
       <h:messages/>
       <h:panelGrid columns="1" id="panel">
       <h:outputText value="#{TestBean.name1}" />
       <h:outputText value="#{TestBean.name2}" />
       </h:panelGrid>
       <p><a4j:commandButton action="#{TestBean.actionOpenPanelClick}"
       reRender="modalPanelContent"
       oncomplete="Richfaces.showModalPanel('edit')"
       value="Edit"/>
       </p>
       </h:form>
      
       <rich:modalPanel id="edit" resizeable="false" autosized="true">
       <f:facet name="header">Edit</f:facet>
       <h:form id="accountAddAdress" xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
      
       <a4j:outputPanel id="modalPanelContent" ajaxRendered="true">
       <rich:messages showDetail="true" showSummary="false" globalOnly="false" />
      
      
       <h:outputText value="Name1" style="float:left;width:110px" />
       <h:inputText id="txtName1" value="#{TestBean.editName1}" rendered="true" required="true"/>
       <h:outputText value="Name2" style="float:left;width:110px" />
       <h:inputText id="txtName2" value="#{TestBean.editName2}" rendered="true" required="true"/>
       <p>
       <a4j:commandButton value="save" action="#{TestBean.actionOk}" reRender="panel,modalPanelContent,mainErrorPanel" oncomplete="closeModalPanel('edit');" limitToList="true"/>
       <a4j:commandButton value="cancel" immediate="true" oncomplete="Richfaces.hideModalPanel('edit');" />
       </p>
      
       </a4j:outputPanel>
       </h:form>
       </rich:modalPanel>
       </body>
      </html>
      


      TestBean.java
      public class TestBean {
       String name1 = null;
       String name2 = null;
      
       String editName1 = null;
       String editName2 = null;
      
       public TestBean(){
       name1 = "Name1";
       name2 = "Name2";
       }
      
       public String actionOpenPanelClick() {
       //Prepare name1 and name2 for editing
       editName1 = name1;
       editName2 = name2;
       return null;
       }
      
       public String actionOk() {
       //Apply data
       System.out.println("save:"+editName1+","+editName2);
       name1 = editName1;
       name2 = editName2;
       return null;
       }
      
       public String getEditName1() {
       return editName1;
       }
      
       public void setEditName1(String editName1) {
       this.editName1 = editName1;
       }
      
       public String getEditName2() {
       return editName2;
       }
      
       public void setEditName2(String editName2) {
       this.editName2 = editName2;
       }
      
       public String getName1() {
       return name1;
       }
      
       public void setName1(String name1) {
       this.name1 = name1;
       }
      
       public String getName2() {
       return name2;
       }
      
       public void setName2(String name2) {
       this.name2 = name2;
       }
      }