Textfield saving blankspaces

I`m using @Valid in my service class, and @NotBlank in my DTO,

Vaadin allow save only blankspaces, how to fix it ?

this is my code now :

            .withValidator(value -> value.isBlank() || value.isEmpty(), "Campo não pode ser vazio").bind(CategoryInsertDTO::getName, CategoryInsertDTO::setName);

Your validator logic is reversed. If the predicate returns true, the value is accepted
it should be value -> !value.isBlank()

assuming that value wil never be null

As an aside, bean validation logic like @Blank is only checked if you use BeanValidationBinder, and then you must bind with String property name, so .bind("name");

In my opinion, bean validation with annotations is more fragile, as you lose compilation time type safety when binding. Only worth using it if you have an existing model with bean validation which is used elsewhere as well

I changed for this.binder.forField(nameField).asRequired(UIUtils.CAMPO_OBRIGATORIO_ERROR_MESSAGE).withValidator( value → !nameField.getValue().isBlank(),“Campo não pode ser em branco”).bind(CategoryInsertDTO::getName, CategoryInsertDTO::setName);

And it worked !

Thx a lot !

I~m using both !

But could you show a example for what u talking about

Flow Binder can’t use the annotation unless you use BeanValidatorBinder instead of regular Binder

And you must use bind(“propertyName”) instead of bind(Bean::getName, Bean::setName)

Is there any place that i can find a example how to implements BeanValidationBinde r?

Vaadin documentation

Search for BeanValidatorBinder

I’m on my phone so I can’t give a link directly

Just change BeanValidationBinder binder = new BeanValidationBinder<>(CategoryInsertDTO.class);

and in this case i can remove .withValidators() ?

You need to change the .bind() call as well

And you must use bind(“propertyName”) instead of bind(Bean::getName, Bean::setName)