5 Replies Latest reply on Jul 26, 2009 2:34 AM by joblini

    home grown data validation

    scphantm.scphantm.gmail.com

      ive spent the past couple of weeks developing a data validation system for my app.  for my needs, the built in validations in seam/jsf/hibernate just simply didn't cut it.  so i wrote a validation engine as a jQuery plugin, wrote my own custom inputText control to pass the browser the data it needs to validate each field, etc. 


      validation for the individual fields are working great.  but one last thing i need is a full page validation when you hit the next button.  each page of my app (about 20 of them) have a previous screen and next screen button.  i need to attach my full page validation routine so that it runs when you click on next but is ignored when you hit previous screen.  now, ive got a click event attached to that button, but even if the validation fails, the pageflow engine still moves you to the next page. 


      can someone please tell me how i can set up my javascript where if the validation returns false it stops the seam/browser from going to the next page?

        • 1. Re: home grown data validation
          asookazian

          I've written custom Seam validator classes for doing live business validation (rather than Hibernate Validators which is domain/entity-specific).  You can use the validator attribute in your JSF component which calls the Seam component's validate method.


          Like this:


          @Name("seamValidatorCodes") 
          @Scope(ScopeType.CONVERSATION)
          @org.jboss.seam.annotations.faces.Validator
          public class SeamValidatorCodes implements javax.faces.validator.Validator, java.io.Serializable
          {
             public void validate(FacesContext context, UIComponent cmp, Object value) throws ValidatorException 
             {     
                  if (foo)
                   throw new ValidatorException(new FacesMessage("this code already exists for this repair Id, please select a different one"));
             }
          }

          • 2. Re: home grown data validation
            scphantm.scphantm.gmail.com

            ok, but ive already written and debugged thousands of lines of javascript code to validate my fields across the whole app and i don't like the idea of having to port it to java so they can run in a bean. 


            all i really need is a way to mark the form invalid.  is there a way i can do something like


            jQuery("form").attr("valid") = false



            ?

            • 3. Re: home grown data validation
              joblini

              Hi Willie,


              In general, returning false from your event handler should cancel the processing.


              Use the JQuery event handling features to cancel the submit of the form.


              Regards,
              Ingo

              • 4. Re: home grown data validation
                scphantm.scphantm.gmail.com

                ok, how would i do that.  i do i capture the form submit event?  problem with that is it would also capture my previous screen button and i will have to jump thru a few hoops to get around that.  which now i typed that wouldn't be so hard.  but how else would i use the event system in jQuery.


                i guess i will just have to test out if capturing the form submit event will mess with the ajax functionality stuff.

                • 5. Re: home grown data validation
                  joblini

                  Are you returning false from the button's onclick event?  I would expect that would to do the trick.