Validation not running properly in Crud UI

I have a entity with such a field.

    @NotEmpty(message = "Username required")
    @Email(message = "Valid email required")
    private String userName;

In my view I am using a GridCrud (v 7.2.0)
For the editor, I have declared

        var form = crud.getCrudFormFactory();
        form.setFieldType("userName", EmailField.class);
        form.setUseBeanValidation(true);

The validation correctly displays the “Username required” message, (SS #1)
however, for an invalid email, it does not display any message (SS #2)

What am I doing wrong?
Thank you


I don’t know any official component named GridCrud. Sounds like an addon, which might get better answers in the appropriate repository of that addon.

General point: it might be possible that the GridCrud is using an EmailField internally, which in this case define its own email validation. This validation takes precedence over yours and needs to be customized.

Yup.
It’s an add on by @alejandro.du and other contributors
https://vaadin.com/directory/component/crud-ui-add-on

If you can get a reference to the EmailField created by the GridCrud, it should be possible to disable the component’s own validation using emailField.setManualValidation(true).

Edit: The “Customization” section on the add-on page lists several methods to customize the generated fields.

1 Like

Update:
After several hours of trial and error, I have concluded, there might be something wrong with the EmailField + @Email combination
When I removed the form.setFieldType("userName", EmailField.class); everything started working properly.
I suppose it defaulted to a TextField since userName is a String.

So basically
EmailField + @Email combination = didn’t work
TextField + @Email combination = worked.

As such, I am marking this topic as resolved

Good to hear you got it solved, @maneesh2 . Thanks for using the add on!