2 Replies Latest reply on Sep 8, 2009 8:27 PM by bharathiya

    How to access Hibernate Validation declarations in Facelet or JSP for JavaScript validation?

    bharathiya

      I am using LiveValidation javascript validation tool for client side validation of the Seam-Facelet application. On the server side, I am using hibernate validation.


      But, I want to use the hibernate validation declaration information (like minimum length, max length etc.) in the javascript.



      Thanks,
      Akanksha



        • 1. Re: How to access Hibernate Validation declarations in Facelet or JSP for JavaScript validation?
          lvdberg

          Seam takes care of the (java-script) interaction with you domain model using Ajax. The big advantage is that you concentrate the validation on the domain-layer and you don't need to copy validation again in the presentation layer. The disadvantage is that it needs interaction with the server, but with present Internet-speed that shouldn't be a point anymore.


          Look at the s:validate tags in the Seam documentation.


           

          • 2. Re: How to access Hibernate Validation declarations in Facelet or JSP for JavaScript validation?
            bharathiya

            We are planning to use the client side validation using the LiveValidation to reduce both the server round-trip and the load on server.


            So I am still looking for ways to access the hibernate declared validations into the javascript validation.


            Also, not able to get the JavaScript alert messages as the loacalised ones.
            I tried 2 ways:
            1.First way:  



            <f:verbatim>
            
            <script language="javascript">
            var firstNameFl= new LiveValidation('course:firstNameFld:firstName');
            firstNameFl.add(Validate.Length, {minimum: 10, failureMessage: "Length must be minimum 10"});
            firstNameFl.add(Validate.Presence, {failureMessage: "Please enter a valid First Name....", validMessage: "ddf"});
            LiveValidation('course:lastNameFld:lastName');
            
            
            var dobFld= new LiveValidation('course:dobFld:dob');
            //This is the attempt to alert some message from the resource bundle
            alert("message from resource bundle: " + #{messages[emailErrorMessage]});                                           
            </script>
            </f:verbatim>
            



            2. Second way: By using an intermediate js file with localised values in it:


            messages.js file




            emailErrorMessage=#{messages[emailErrorMessage]};






            And then, using this in the LiveValidation:



            <f:verbatim>
            <script language="javascript">
            var firstNameFl= new LiveValidation('course:firstNameFld:firstName');
            firstNameFl.add(Validate.Length, {minimum: 10, failureMessage: "Length must be minimum 10"});
            firstNameFl.add(Validate.Presence, {failureMessage: "Please enter a valid First Name....", validMessage: "ddf"});
            var dobFld= new LiveValidation('course:dobFld:dob');
            alert("message from resource bundle: " + emailErrorMessage );                                       
                                                        </script>
                                                    </f:verbatim>


            Please suggest.