How to validate fields

I created myValidator:

public class EmptyNullValidator implements Validator<Object> {
    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");
   		 withValidator(new EmptyNullValidator())
   		.withValidationStatusHandler((s) -> {
   		  //smth do
   		.bind(new ValueProvider<User, String>() {
   			public String apply(User user) {
   				return user.getLogin();
   		}, new Setter<User, String>() {
   			public void accept(User user, String s) {

But I get the result if any input was made in the field.

And with component PasswordField validate not working at all.

At quick glance I did not notice why your code is not working. But in your use case you could asRequired(…) instead, see

it works if the field changes the user.I need this to work when the field appears before the interaction\