Created
November 7, 2016 20:59
-
-
Save hendrikebbers/3a4fb58c5384638b6b34affe3b6b0228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormController extends AbstractFormController { | |
private final Validator validator; | |
private ValidatedValues<FormModel> v; | |
public FormController(Validator validator) { | |
this.validator = validator; | |
v = ValidatedValues.build(FormModel.class). | |
withProperty("firstName", () -> getFirstNameTextField().getText(), v -> updateForValidation(getFirstNameTextField(), v)). | |
withProperty("lastName", () -> getLastNameTextField().getText(), v -> updateForValidation(getLastNameTextField(), v)). | |
withProperty("active", () -> getActiveCheckBox().isSelected(), v -> updateForValidation(getActiveCheckBox(), v)). | |
withProperty("gender", () -> getGenderChoiceBox().getValue(), v -> updateForValidation(getGenderChoiceBox(), v)); | |
} | |
@Override | |
protected void validate() { | |
Set<ConstraintViolation<FormModel>> violations = validator.validate(v, UIGroup.class); | |
if(violations == null || violations.isEmpty()) { | |
System.out.println("We have no violations!"); | |
FormModel model = updateModelByUI(); | |
// Send model to server... | |
} else { | |
System.out.println("We have violations!"); | |
violations.forEach(v -> System.out.println(v.getMessage())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment