As per one of the answers (How to translate validation messages - CUBA.Platform), I implemented a validator programatically for a Field based on com.haulmont.cuba.gui.components.Field.Validator. The field was required.
If I don’t specify a required message for when it is empty, the actual message for when it fails the validator doesn’t show up.
usernameField.addValidator(new Field.Validator() {
private final String EMAIL_REGEX =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private final Pattern PATTERN = Pattern.compile(EMAIL_REGEX);
@Override
public void validate(Object value) throws ValidationException {
String email = value.toString();
if ((value == null) || "".equals(email) || !PATTERN.matcher(email).matches()) {
throw new ValidationException("The username must be a valid email address");
}
}
});
For example, what I’m finding is that if you don’t specify a required message like:
passwordField.setRequiredMessage("The password cannot be empty");
The alert notification comes up empty when it fails the valid email test. If you do set a required message, then the “The username must be a valid email address” message comes up properly when the field is non-empty but doesn’t contain a valid email.
BTW, is this the place to post bug reports or should I post them somewhere else?