cleanup
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / data / validator / PasswordsMatchValidator.java
1 /**
2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.vaadin.data.validator;
10
11 import com.vaadin.data.validator.AbstractStringValidator;
12 import com.vaadin.ui.PasswordField;
13
14 /**
15 * Checks that the passwords entered in two password fields match.
16 * Intended to be added as validator to the second field of the
17 * {@link PasswordField} pair.
18 *
19 * @author a.kohlbecker
20 * @since Nov 12, 2021
21 */
22 public class PasswordsMatchValidator extends AbstractStringValidator {
23
24 private static final long serialVersionUID = -9048318480638222817L;
25
26 private PasswordField firstField;
27 private PasswordField secondField;
28
29 public PasswordsMatchValidator(String errorMessage, PasswordField firstField, PasswordField secondField) {
30 super(errorMessage);
31 this.firstField = firstField;
32 this.secondField = secondField;
33 firstField.addValueChangeListener(event -> {
34 getErrorMessage();
35 });
36 }
37
38 @Override
39 protected boolean isValidValue(String value) {
40 return firstField.getValue().equals(secondField.getValue());
41 }
42 }