Search code examples
regexvaadincustomvalidator

Vaadin RegexpValidator multiple error message


Is it possible to return conditional error message for a vaadin validator?

TextField textField = new TextField();
String regex = "?:(foo|bar)";
textField.addValidator(new RegexpValidator(regex, true, getErrorMessage()));

I want to have a different error message depending on what the user write in the textField.


Solution

  • I found the solution. One should just override the getErrorMessage of the validator

    textField.addValidator(new RegexpValidator(regex, true, "") {   
            @Override
            public String getErrorMessage() {
                 return setMessage();
            }
    });