Skip to content
Snippets Groups Projects
Commit f6283658 authored by Goik Martin's avatar Goik Martin
Browse files

pasword match test seems to work

parent 3fd9b3d1
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,7 @@ public class Register extends CustomComponent implements View, ValidateGlobal {
mainLayout.addComponents(password1Field);
password2Field.addValidator(new ValidateSecondIdenticalInput(password1Field));
password1Field.addValidator(new ValidateSecondIdenticalInput(password2Field));
mainLayout.addComponents(password2Field);
{// Preparing cancel/OK buttons
......
package de.hdm_stuttgart.mi.tools;
import com.vaadin.data.Validator;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.Field;
public class ValidateSecondIdenticalInput implements Validator {
......@@ -15,8 +16,29 @@ public class ValidateSecondIdenticalInput implements Validator {
@Override
public void validate(Object value) throws InvalidValueException {
if (! (value instanceof String) || ! value.equals(reference.getValue())){
throw new InvalidValueException("Passwords do not match");
if (null != value && ! (value instanceof String)) {
throw new InvalidValueException("Field is not of string type");
} else if (null != reference.getValue() && ! (reference.getValue() instanceof String)) {
throw new InvalidValueException("Comparison field is not of string type");
} else {
final String stringValue, referenceStringValue;
if (null == value) {
stringValue = "";
} else {
stringValue = ((String) value);
}
if (null == reference.getValue()) {
referenceStringValue = "";
} else {
referenceStringValue = ((String) reference.getValue());
}
if (!referenceStringValue.equals("") && ! stringValue.equals(referenceStringValue)) {
throw new InvalidValueException("Passwords do not match");
} else {
((AbstractField<?>)reference).setComponentError(null);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment