Reputation: 2250
In the book of Vaadin I read the following:
Validating a bean is done with a BeanValidator, which you initialize with the name of the bean property it should validate and add it the the editor field. The validation is done immediately after focus leaves the field. Bean validators are automatically created when using a BeanFieldGroup.
So here's my BeanFieldGroup:
BeanFieldGroup<OrderSearchCriteria> binder = new BeanFieldGroup<>(OrderSearchCriteria.class);
binder.setItemDataSource(searchCriteria);
And this is how I've added validation on my bean:
@Min(0)
private BigDecimal minAmount;
@Min(0)
private BigDecimal maxAmount;
@Pattern(regexp = "([a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]{2,})?")
private String email;
Validation is not automatically added as I thought it would. So what am I missing?
Upvotes: 0
Views: 164
Reputation: 2250
You need to download an implementation of a bean validator, and then things will start working out of the box.
If you're using maven and want to use hibernate-validator you would simply add a dependency in your pom.xml file like this:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.0.Final</version>
</dependency>
References:
Upvotes: 1