5 Replies Latest reply on Feb 13, 2009 11:45 PM by binnyg

    Easy question : Problem submitting form with double value.

    valatharv
      I have a form with text field (datatype double) which can be multiple.
      I need to provide validation that this field can only be double and cannot be null, once "Save" button is clicked on submitting the form.
      I cannot use a4j / onblur as screen is complex and this can be multiple textfields.

      Issue :
      When I fill this field as varchar or leave it null. On Clicking "Save" (it calls persist) nothing happens, page is not submitted and
      I can't even see the SOP as given in xxxxHome.persist().

      Please suggest how can I handle this.

      <ui:repeat value="#{treatmentHome.xxxx}" var="itreat">
           <h:inputText value="#{itreat.treatmentConcentration}"/>
           ... THIS IS DYNAMIC AND CAN BE MULTIPLE
      </ui:repeat>

      public String persist(){          
                System.out.println("Persist ENTERED");
                .....
                return super.persist();
      }

      @Entity(name = "Treatment")
      public class Treatment implements Equals, HashCode, ToString {
                protected double treatmentConcentration;
                @Basic
                @Column(name = "TREATMENTCONCENTRATION")
                public double getTreatmentConcentration() {
                     return treatmentConcentration;
                }
      }
        • 1. Re: Easy question : Problem submitting form with double value.

          Try this


          <h:inputText value="#{itreat.treatmentConcentration}" required="true">
             <f:converter id="javax.faces.Double"/>
          </h:inputText>
          



          You can Hibernate validator with your entities.

          • 2. Re: Easy question : Problem submitting form with double value.
            valatharv
            I tried as suggested, issue is same "When I fill this field as varchar or leave it null. On Clicking "Save" (it calls persist) nothing happens, page is not submitted and
            I can't even see the SOP as given in xxxxHome.persist()."

            I checked "persistence-dev.xml" "hibernate.hbm2ddl.auto" entry was missing, so I added this "<property name="hibernate.hbm2ddl.auto" value="validate"/>" to persistence-dev.xml

            Now, when I restart Jboss, I am getting this error..
            -------------------------
            [ServiceController] Problem starting service persistence.units:ear=appSeam.ear,jar=appSeam.jar,unitName=appSeam
            javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: TREATMENTCONCENTRATION, expected: double precision
            -------------------------

            I am missing some basic settings.

            This is entity.
            @Entity(name = "Treatment")
            public class Treatment implements Equals, HashCode, ToString {
              protected double treatmentConcentration;
              @Basic
              @Column(name = "TREATMENTCONCENTRATION")
              public double getTreatmentConcentration() {
               return treatmentConcentration;
              }
            }


            • 3. Re: Easy question : Problem submitting form with double value.

              If you are using hibernate then you should leverage hibernate validator.


              @Entity(name = "Treatment")
              public class Treatment implements Equals, HashCode, ToString {
                
                protected double treatmentConcentration;
                
                @NotNull
                @Column(name = "TREATMENTCONCENTRATION", nullable = false)
                public double getTreatmentConcentration() {
                 return treatmentConcentration;
                }
              }
              



              In xhtml wrap your form fields with s:validate.



              <s:validate>
                <input type="text" value="#{itreat.treatmentConcentration}"/>
              </s:validate> 



              Also, add h:messages to see the error message.

              • 4. Re: Easy question : Problem submitting form with double value.
                valatharv
                <s:validate>
                <h:inputText value="#{itreat.treatmentConcentration}" requiredMessage="Please enter as number">                                  
                </h:inputText>
                </s:validate>

                Gives exception on page loadd itself as :

                Caused by: com.sun.facelets.tag.TagException: /xxxxEdit.xhtml @324,37 <s:validate> Parent not an instance of EditableValueHolder: com.sun.facelets.component.UIRepeat@1e7e7e8
                • 5. Re: Easy question : Problem submitting form with double value.

                  I can help you better if I can see your xhtml file.