}
}
*/
public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
RegisterCustomerForm form = (RegisterCustomerForm) obj;
Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername());
if (customerFromDb != null) {
if (useEmailForUsername) {
errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null);
} else {
errors.rejectValue("customer.username", "username.used", null, null);
}
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
errors.pushNestedPath("customer");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
errors.popNestedPath();
if (!errors.hasErrors()) {
if (!form.getPassword().matches(getValidatePasswordExpression())) {
errors.rejectValue("password", "password.invalid", null, null);
}
if (!form.getPassword().equals(form.getPasswordConfirm())) {
errors.rejectValue("password", "passwordConfirm.invalid", null, null);
}
if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) {
errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null);
}
}
}