문제

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
도움이 되었습니까?

해결책

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.

다른 팁

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>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top