Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Required vs @NotNull
i have a form with a textField name binded with a property name of a bean annotated with @NotNull (message="This field is required").
If i put the field with setRequired (to see the required indicator *) without setRequiredError then the field doesn't validate the not null constraint.
Is it incompatible setRequired with NotNull annotation?
@NotNull is practically equal to required flag Vaadin field, which is kind of built in Validator executed before any other validators. In Viritin all fields bound to @NotNull annotated properties are automatically made required. It might be a good enhancement to this, to "steal" the validation error message from NotNull annotation if present?
i don't understand what you want to say with steal the validation error message.
@NotNull annotation in a property automatically put a required indicator to the textField that is bind it.
But it I left blank the textfield i can't see any errorMessage. It shouldn't be a errorValidation ?
In a Person class
@NotNull (message = "Introduce tu nombre") private String name;
BeanValidationBinder<Person> binder = new BeanValidationBinder<>(Person.class); binder.forField(nameField).bind(Person::getName, Person.setName);
@NotNull doesn't work, i can't see the required indicator.
Anothe possibility is to put .asRequired but what doest it happen with @NotNull?
In the doc says
The validator is by default run whenever the user changes the value of the field. So if the user doesn't write anything in the required field we only see the requieredIndicator. I must to manual validate to see the error message.