How to validate fields

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.

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

https://vaadin.com/api/platform/12.0.3/com/vaadin/flow/data/binder/Binder.BindingBuilder.html#asRequired--

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