0 Replies Latest reply on May 17, 2011 9:47 AM by Ruben Lopez

    How to use Hibernate Validator in Seam Home object?

    Ruben Lopez Newbie

      Hi everyone.


      Sorry if this is not a seam specific question but I don't know where else to ask.


      I have the following code that should produce a validation failure but it doesn't work.


      @Name("departamentoHome")
      public class DepartamentoHome extends EntityHome<Departamento> {
      
           ...
      
           @Override
           public String persist() {
                
      
                // set invalid value (getCodigo() is annotated with @NotNull)
                getInstance().setCodigo(null);
      
                
                ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
                Validator validator = factory.getValidator();
      
                //validation should fail
                Set<ConstraintViolation<Departamento>> constraintViolations = validator.validate(getInstance());
                
                if (!constraintViolations.isEmpty()) {
                     facesMessages.add(Severity.ERROR,
                               "Validation failed");
                     return null;
                }
      
                return super.persist();
           }
      }



      What am I doing wrong?


      The reason for doing the validation here is that I have implemented a custom class level constraint and I need to check it before persisting the entity. My constraint didn't worked, then I tested my aplication with this simple constraint but it didn't worked either.


      I use:



      • Jboss Seam 2.2.1.Final

      • Jboss AS 6.0.0.Final



      Thanks in advance.