Question

I'm trying create an application using Maven and Vaadin Bean Validation to validate my beans, but doesn't now work to me.

I'm trying this.

@Entity
public class Person{
    @Id
    @GeneratedValue
    private Integer id;

    @NotNull
    @NotEmpty
    @Size(min=5, max=50, message="insert first name")
    private String firstName;

    @NotNull
    @NotEmpty
    @Email
    private String email;

}

//my app
public class LoginView extends VerticalLayout{
     private TextField firstName, email;
     private BeanFieldGroup<Person> binder;
     private FormLayout form;

     public LoginView(){
         form = new FormLayout();
         binder = new BeanFieldGroup<Person>(Person.class);
         Field<?> field = null;

         field = binder.buildAndBind("Firstname", "firstName");
         firstName = (TextField)binder.getField("firstName");
         form.addComponent(firstName);

         field = binder.buildAndBind("Email", "email");
         email = (TextField)binder.getField("email");
         form.addComponent(email);

         this.addComponent(form);
     }
}

I added hibernate-validator as dependecy but still doesn't work. In vaadin bean validator documents says to use Hibernate Validator or agimatec-validation.

enter image description here

Which dependency I need to add for this work ?

The method isBeanValidationImplementationAvailable() returns true, Debug is bellow.

11:26:54,112 DEBUG [org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver] - Found javax.persistence.Persistence on classpath containing 'getPersistenceUtil'. Assuming JPA 2 environment. Trying to instantiate JPA aware TraversableResolver
11:26:54,113 DEBUG [org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver] - Instantiated JPA aware TraversableResolver of type org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.
11:26:54,113 DEBUG [org.hibernate.validator.internal.xml.ValidationXmlParser] - Trying to load META-INF/validation.xml for XML based Validator configuration.
11:26:54,113 DEBUG [org.hibernate.validator.internal.xml.ValidationXmlParser] - No META-INF/validation.xml found. Using annotation based configuration only.
Is bean validation implementation available: true
Was it helpful?

Solution

It should validate when you call binder.commit(). Check out if you have javax.validation.Validation class on the classpath.

If it's not the case, please debug the isBeanValidationImplementationAvailable() static method on BeanFieldGroup and post any further details you found out.

OTHER TIPS

You need to use the BeanValidationForm and BeanValidationValidator that come along with the Vaadin Bean Validation addon. You'll find some demo code at svn for this addon.

I had same problem, decided with included in dependencies <artifactId>javaee-api</artifactId>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top