Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Validation failure message for TextField in Grid not shown

chahat bhatia
5 years ago Sep 21, 2016 11:00am
Alejandro Duarte
5 years ago Sep 21, 2016 1:36pm

Hi,

Try using a custom field factory and add a custom "number validator" when required. For example:

beanFieldGroup.setFieldFactory(new DefaultFieldGroupFieldFactory() {

    @Override
    public <T extends Field> T createField(Class<?> dataType, Class<T> fieldType) {
        T field = super.createField(dataType, fieldType);

        if (Number.class.isAssignableFrom(dataType)) {
            field.addValidator(value -> {
                if (value != null && !value.toString().isEmpty() && !value.toString().matches("-?\\d+(\\.\\d+)?")) {
                    throw new InvalidValueException("Please specify a number");
                }
            });
        }

        return field;
    }
});
chahat bhatia
5 years ago Sep 21, 2016 6:03pm
chahat bhatia
5 years ago Sep 21, 2016 6:32pm
Alejandro Duarte
5 years ago Sep 22, 2016 10:06am
chahat bhatia
5 years ago Sep 22, 2016 10:28am
Alejandro Duarte
5 years ago Sep 22, 2016 10:35am
chahat bhatia
5 years ago Sep 22, 2016 12:09pm
Alejandro Duarte
5 years ago Sep 22, 2016 12:28pm

You are using the "reindeer" theme. Unless, the "valo" theme, I think "reindeer" won't change the look of the field when a validation fails, but you should see a tooltip with the error when the validation fails if you put the mouse pointer over the field.

chahat bhatia
5 years ago Sep 22, 2016 12:32pm

Hehe Bingo:) 

I knew it was some tiny detail we were missing. 

Thanks a lot, Bringing the mouse curser I do see the error. 

jeremy zurcher
5 years ago Apr 07, 2017 1:15pm
Alejandro Duarte
4 years ago May 05, 2017 2:34pm
jeremy zurcher
4 years ago May 09, 2017 12:53pm
Alejandro Duarte
4 years ago May 10, 2017 6:49am