Validators vs bean validation

In the docs it is said …
The validation state of each field is updated whenever the user modifies the value of that field.
So if i have a validator registered in a textfield wich is binded to a property I can see the error message after i wrote the name field with less than 4 characters.
[font]

Binder<Person> binder = new Binder<>();
TexField name = new TextField();
binder.forField(name)
      .withValidator( n -> n.length() < 4,
                      "name must have at least 4 characters")
      .bind(Person::getName, Person::setName)

[/font]

But if i use bean validation i can’t see the same.

@Size(min = 4, message = "name must have at least 4 characters")
String name

BeanValidationBinder<Person> binder = new BeanvalidationBinder<>(Person.class); binder.bindInstanceFields(form); I thougth that it was the same because BeabValidationBinder extends Binder.
So in that case when does it happen the validation?

Do you have a Java Bean Validation implementation in your classpath? For example:

<dependency>
  <groupId>org.apache.geronimo.specs</groupId>
  <artifactId>geronimo-validation_1.0_spec</artifactId>
  <version>1.1</version>
</dependency>
<dependency>
  <groupId>org.apache.bval</groupId>
  <artifactId>org.apache.bval.bundle</artifactId>
  <version>0.5</version>
</dependency>

In my POM i have the next dependency

<dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>2.0.0.Final</version> </dependency> I believed that it was enough.

Yes, javax.validation is valid alternative to org.apache.bval. But you need to have implementation in addition to API, e.g.

org.hibernate hibernate-validator …

Vaadin Binder support JSR-303 versions 1.0 and 1.1, you need to double check that too.

Actually,
Apache Bval
is an implementation.

So, Java Validation API is a specification (that’s the
validation-

api
dependency). You need also an implementation. Two popular implementations are the ones provided by Apache (the dependencies I posted), and Hibernate (the ones Tatu posted). Let us know if it works!

It doesn´t work, something escape me!!!
I have in the POM the two dependencies (api and implementation of bean validation)

<dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>2.0.0.Final</version> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> <version>6.0.5.Final</version> </dependency> What is the moment in wich the validation trigger the error message?
After the user update the field (that it was happening with .withvalidator.
In the doc it is said …

Bean level validation can only be performed once the bean has been updated. This means that this functionality can only be used together with setBean. I am not sure what bean level means. My annotation is in the property name of the bean person.

“Bean level validation” are constraints at the class level. So I guess, it’s not your case (you have a field-level constraint: @Size). With Hibernate Validator you also need this if you are not deploying your app in a JEE container:

<dependency> <groupId>org.glassfish</groupId> <artifactId>javax.el</artifactId> <version>3.0.1-b08</version> </dependency> If that doesn’t work, are you able to share the complete
pom.xml
file and relevant Java classes?

when you write about JEE container a ligth turned it on. I use wildfly so i use the bean validation provided by wildfly.

<dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-bean-validation</artifactId>
            <version>11.0.0.Final</version>
            <scope>provided</scope>
 </dependency>

Now it works but i was surprised about the * in the fields with annotation. It appears first * (like required) and ! (when the user begin to write the three first characters).
What is the meaning of this *? It isnt required beacause the only annotation was @Size.

Ups !!!
It doesn’t work with same annotations like @NotNull but it works with others like @Size ???

It should work for all of them. Did you configure a “null representation”? Also, double check you imported the correct
@NotNull
annotation (
javax

.validation.constraints.NotNull
).

Thank you Alejandro,
hibernate-validator is enough with a JEE container (wildfly) and withNotNullRepresentation(“”) at least works @NotNull constraint