diff --git a/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormView.java b/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormView.java index f3dc72502..de1609d9b 100644 --- a/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormView.java +++ b/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormView.java @@ -44,7 +44,7 @@ public void initialize() { phoneNumberInput.textProperty().bindBidirectional(viewModel.phoneNumberProperty()); emailInput.textProperty().bindBidirectional(viewModel.emailProperty()); birthdayInput.valueProperty().bindBidirectional(viewModel.birthdayProperty()); - + validationVisualizer.initVisualization(viewModel.firstnameValidation(), firstnameInput, true); validationVisualizer.initVisualization(viewModel.lastnameValidation(), lastnameInput, true); validationVisualizer.initVisualization(viewModel.birthdayValidation(), birthdayInput); diff --git a/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormViewModel.java b/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormViewModel.java index 5e5a8bda6..debcb7604 100644 --- a/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormViewModel.java +++ b/examples/mvvmfx-contacts/src/main/java/de/saxsys/mvvmfx/contacts/ui/contactform/ContactFormViewModel.java @@ -23,27 +23,27 @@ public class ContactFormViewModel implements ViewModel { private Validator phoneValidator = new PhoneValidator(phoneNumberProperty(), "The phone number is invalid!"); private Validator mobileValidator = new PhoneValidator(mobileNumberProperty(), "The mobile number is invalid!"); - + private CompositeValidator formValidator = new CompositeValidator(); public ContactFormViewModel() { - firstnameValidator = new FunctionBasedValidator<>( - firstnameProperty(), - firstName -> firstName != null && !firstName.trim().isEmpty(), - ValidationMessage.error("Firstname may not be empty")); - - - lastnameValidator = new FunctionBasedValidator<>(lastnameProperty(), lastName -> { - if(lastName == null || lastName.isEmpty()) { - return ValidationMessage.error("Lastname may not be empty"); - } else if(lastName.trim().isEmpty()) { - return ValidationMessage.error("Lastname may not only contain whitespaces"); - } - - return null; - }); - - + firstnameValidator = new FunctionBasedValidator<>( + firstnameProperty(), + firstName -> firstName != null && !firstName.trim().isEmpty(), + ValidationMessage.error("Firstname may not be empty")); + + + lastnameValidator = new FunctionBasedValidator<>(lastnameProperty(), lastName -> { + if (lastName == null || lastName.isEmpty()) { + return ValidationMessage.error("Lastname may not be empty"); + } else if (lastName.trim().isEmpty()) { + return ValidationMessage.error("Lastname may not only contain whitespaces"); + } + + return null; + }); + + formValidator.addValidators( firstnameValidator, lastnameValidator, @@ -56,20 +56,20 @@ public ContactFormViewModel() { public void resetForm() { contactWrapper.reset(); } - + public void initWithContact(Contact contact) { this.contactWrapper.set(contact); this.contactWrapper.reload(); } public Contact getContact() { - - if(contactWrapper.get() == null) { + + if (contactWrapper.get() == null) { contactWrapper.set(new Contact()); } - + contactWrapper.commit(); - + return contactWrapper.get(); } @@ -84,11 +84,11 @@ public ValidationStatus lastnameValidation() { public ValidationStatus birthdayValidation() { return birthdayValidator.getValidationStatus(); } - - public ValidationStatus emailValidation() { - return emailValidator.getValidationStatus(); - } - + + public ValidationStatus emailValidation() { + return emailValidator.getValidationStatus(); + } + public ValidationStatus phoneValidation() { return phoneValidator.getValidationStatus(); } @@ -132,8 +132,8 @@ public StringProperty mobileNumberProperty() { public StringProperty phoneNumberProperty() { return contactWrapper.field("phoneNumber", Contact::getPhoneNumber, Contact::setPhoneNumber); } - - public BooleanExpression validProperty() { - return formValidator.getValidationStatus().validProperty(); - } + + public BooleanExpression validProperty() { + return formValidator.getValidationStatus().validProperty(); + } } diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/CrossFieldExampleApp.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/CrossFieldExampleApp.java index e75157dd7..79510bcd3 100644 --- a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/CrossFieldExampleApp.java +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/CrossFieldExampleApp.java @@ -14,7 +14,7 @@ * @author manuel.mauky */ public class CrossFieldExampleApp extends Application { - + public static void main(String... args) { launch(args); } diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormView.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormView.java index 4381301a5..3dac00b55 100644 --- a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormView.java +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormView.java @@ -15,7 +15,7 @@ * @author manuel.mauky */ public class RegisterFormView implements FxmlView { - + @FXML public PasswordField pwInput; @FXML @@ -24,10 +24,10 @@ public class RegisterFormView implements FxmlView { public Label message; @FXML public Button okButton; - + @InjectViewModel private RegisterFormViewModel viewModel; - + public void initialize() { diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormViewModel.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormViewModel.java index 8a6827f3e..81a9a4c30 100644 --- a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormViewModel.java +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/validation/crossfieldexample/RegisterFormViewModel.java @@ -17,7 +17,7 @@ public class RegisterFormViewModel implements ViewModel { private StringProperty password = new SimpleStringProperty(); private StringProperty passwordRepeat = new SimpleStringProperty(); - + private ObservableRuleBasedValidator passwordValidator = new ObservableRuleBasedValidator(); @@ -30,33 +30,33 @@ public RegisterFormViewModel() { passwordValidator.addRule(rule2, ValidationMessage.error("Please enter the password a second time")); passwordValidator.addRule(rule3, ValidationMessage.error("Both passwords need to be the same")); } - + public ValidationStatus getValidation() { return passwordValidator.getValidationStatus(); } - + public String getPassword() { return password.get(); } - + public StringProperty passwordProperty() { return password; } - + public void setPassword(String password) { this.password.set(password); } - + public String getPasswordRepeat() { return passwordRepeat.get(); } - + public StringProperty passwordRepeatProperty() { return passwordRepeat; } - + public void setPasswordRepeat(String passwordRepeat) { this.passwordRepeat.set(passwordRepeat); } - + }