Password equals validator

Hello guys,

I need to code custom validator to compare 2 passwords in registration form. I am quite new in Vaadin and it s not very clear for me to understand how validators in vaadin works. I got something but it doesnt work.

public class PasswordEqualsValidator implements Validator {

	private static final long serialVersionUID = 1L;
	private String pass;
	private String rePass;
	
	public PasswordEqualsValidator(String pass, String rePass) {
		pass = this.pass;
		rePass = this.rePass;			
	}

	@Override
	public void validate(Object value) throws InvalidValueException {
		if (!isValid(value))
            throw new InvalidValueException("Passwords is not equals");			
	}

	@Override
	public boolean isValid(Object value) {
		if(pass.equals(rePass)) {
			return true;
		} else {
			return false;
		}
	}		
}

Help If U can

I don’t think you want to give the validator Strings as input, otherwise you need to create a new one every time either String changes… It’s better if your validator has access to the fields in question and can use field.getValue() to get the current values.