3 Replies Latest reply on Feb 20, 2008 10:48 AM by mail.micke

    How works validation?

    pettersonfp

      Hello,


      When you annotate a bean (i.e.: using @Range), when the validation fails, seam put a message in the proper field of the form.  How is that accomplished? 


      I would like to perform validations during the execution of an action that cannot be put in a Validator, is it possible to throw some exception during the validation that will be shown at the form as a message?


      Thanks in advance,


      Petterson

        • 1. Re: How works validation?
          nickarls

          Petterson Paula wrote on Feb 20, 2008 07:25 AM:


          Hello,

          When you annotate a bean (i.e.: using @Range), when the validation fails, seam put a message in the proper field of the form.  How is that accomplished? 

          I would like to perform validations during the execution of an action that cannot be put in a Validator, is it possible to throw some exception during the validation that will be shown at the form as a message?

          Thanks in advance,

          Petterson


          Well, you could always write a standard JSF validator (manually or through Seam) but if you look at the Hibernate Validator docs, it is hard to find stuff that can't be done with custom validators there.

          • 2. Re: How works validation?
            mail.micke

            Yepp,
            you can do validation in the action method and display messages.




            @In
            FacesMessages facesMessages;
            
            




            // In your action, not important to specify correct component id
            facesMessages.addToControl(
               "serverSideForm:endDate",
               new FacesMessage(FacesMessage.SEVERITY_ERROR, "message summary","message details")
               );
            return null;
            



            Can't quite remeber if the order of the message detail/summary parameters.


            There is some informatin about this here (not using seam):
            Tutorial



            Good luck

            • 3. Re: How works validation?
              mail.micke

              Small type with severe consequences...


              This


              // In your action, not important to specify correct component id


              Should be


              // In your action, note important to specify correct component id


              :)