I created myValidator:
public class EmptyNullValidator implements Validator<Object> {
@Override
public ValidationResult apply(Object value, ValueContext context) {
try {
if (value == null) throw new Exception();
if (((String) value).isEmpty()) throw new Exception();
} catch (Exception e) {
return ValidationResult.error("Empty field");
}
return ValidationResult.ok();
}
}
and I need the result of the check until the user even entered anything in the field.
TextField login = new TextField("Login");
binder.forField(login).
withValidator(new EmptyNullValidator())
.withValidationStatusHandler((s) -> {
//smth do
})
.bind(new ValueProvider<User, String>() {
@Override
public String apply(User user) {
return user.getLogin();
}
}, new Setter<User, String>() {
@Override
public void accept(User user, String s) {
user.setLogin(s);
}
});
But I get the result if any input was made in the field.
And with component PasswordField validate not working at all.