List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:de.hybris.platform.acceleratorservices.web.payment.validation.PaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final PaymentDetailsForm form = (PaymentDetailsForm) object; final Calendar start = parseDate(form.getStartMonth(), form.getStartYear()); final Calendar expiration = parseDate(form.getExpiryMonth(), form.getExpiryYear()); final Calendar current = Calendar.getInstance(); if (start.after(current)) { errors.rejectValue("startMonth", "payment.startDate.past.invalid"); }//from w w w . j a v a 2s .co m if (expiration.before(current)) { errors.rejectValue("expiryMonth", "payment.expiryDate.future.invalid"); } if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity", "address.city.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode", "address.postcode.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso", "address.country.invalid"); }
From source file:de.hybris.platform.acceleratorservices.web.payment.validation.SopPaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final SopPaymentDetailsForm form = (SopPaymentDetailsForm) object; final Calendar startOfCurrentMonth = getCalendarResetTime(); startOfCurrentMonth.set(Calendar.DAY_OF_MONTH, 1); final Calendar startOfNextMonth = getCalendarResetTime(); startOfNextMonth.set(Calendar.DAY_OF_MONTH, 1); startOfNextMonth.add(Calendar.MONTH, 1); final Calendar start = parseDate(form.getCard_startMonth(), form.getCard_startYear()); final Calendar expiration = parseDate(form.getCard_expirationMonth(), form.getCard_expirationYear()); if (start != null && !start.before(startOfNextMonth)) { errors.rejectValue("card_startMonth", "payment.startDate.invalid"); }/* ww w. j a v a2 s. c om*/ if (expiration != null && expiration.before(startOfCurrentMonth)) { errors.rejectValue("card_expirationMonth", "payment.startDate.invalid"); } if (start != null && expiration != null && start.after(expiration)) { errors.rejectValue("card_startMonth", "payment.startDate.invalid"); } if (StringUtils.isBlank(form.getBillTo_country())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_country", "address.country.invalid"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_street1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_city", "address.city.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_postalCode", "address.postcode.invalid"); } }
From source file:de.ingrid.admin.controller.GeneralController.java
@RequestMapping(value = IUris.GENERAL, method = RequestMethod.POST) public String postGeneral(final ModelMap modelMap, @ModelAttribute("plugDescription") final PlugdescriptionCommandObject commandObject, final Errors errors, @ModelAttribute("partners") final List<Partner> partners) throws Exception { String newPW = (String) errors.getFieldValue("newPassword"); String currentPW = JettyStarter.getInstance().config.pdPassword; // only reject empty password if no password has been configured yet at all! if ((currentPW == null || currentPW.isEmpty()) && (newPW.isEmpty())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPassword", AbstractValidator .getErrorKey(PlugdescriptionCommandObject.class, "newPassword", IErrorKeys.EMPTY)); }//from w w w . j a v a 2 s . c o m // if no connection to iBus or no partners could be fetched then ignore the partner field!!! if (_validator.validateGeneral(errors, !_communicationService.hasErrors() && !partners.isEmpty()) .hasErrors()) { return getGeneral(modelMap, commandObject, errors, partners); } setConfiguration(commandObject); // add forced datatypes addForcedDatatypesToConfig(); // add data type includes addIncludedDataTypes(_dataTypes); return redirect(IUris.PARTNER); }
From source file:de.iteratec.iteraplan.presentation.dialog.common.model.RoutingDatasourceComponentModel.java
public void validate(Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedDataSource", "NAME_CANNOT_BE_EMPTY"); }
From source file:net.sf.sail.webapp.presentation.validators.ChangePasswordParametersValidator.java
public void validatePasswd1(Errors errors, ChangePasswordParameters params) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwd1", "error.no-password"); if (errors.getErrorCount() != 0) return;//from ww w .ja va 2 s .com this.validatePasswordAlphaNumeric(errors, params.getPasswd1()); }
From source file:net.sf.sail.webapp.presentation.validators.ChangePasswordParametersValidator.java
public void validatePasswd2(Errors errors, ChangePasswordParameters params) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwd2", "error.no-password"); if (errors.getErrorCount() != 0) return;/*from w ww.j a va 2s . c om*/ this.validatePasswordAlphaNumeric(errors, params.getPasswd2()); }
From source file:net.sf.sail.webapp.presentation.validators.GroupParametersValidator.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) *///from w w w . ja v a 2 s . c om public void validate(Object groupParametersIn, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.groupname.not-specified"); if (errors.getFieldErrorCount("name") > 0) { return; } GroupParameters groupParameters = (GroupParameters) groupParametersIn; if (!StringUtils.isAlphanumeric(groupParameters.getName())) { errors.rejectValue("name", "error.groupname.illegal-characters"); } if (groupParameters.getName().length() > MAX_GROUP_NAME_LENGTH) { errors.rejectValue("name", "error.groupname.too-long"); } if (groupParameters.getParentId() < 0) { errors.rejectValue("parentId", "error.groupparent.must-be-non-negative"); } }
From source file:net.sf.sail.webapp.presentation.validators.OfferingParametersValidator.java
public void validate(Object offeringParametersIn, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.offeringname-not-specified"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "curnitId", "error.offeringcurnitid-not-specified"); if (errors.hasErrors()) { return;/*from ww w . ja v a 2 s . co m*/ } OfferingParameters offeringParameters = (OfferingParameters) offeringParametersIn; if (!StringUtils.isAlphanumericSpace(offeringParameters.getName())) { errors.rejectValue("name", "error.offeringname-illegal-characters"); return; } if (offeringParameters.getName().length() > MAX_OFFERINGNAME_LENGTH) { errors.rejectValue("name", "error.offeringname-too-long"); return; } if (offeringParameters.getCurnitId() < 1) { errors.rejectValue("curnitId", "error.offeringcurnitid-too-small"); return; } }
From source file:net.sf.sail.webapp.presentation.validators.UserDetailsValidator.java
public void validate(Object userDetailsIn, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.not-specified"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.not-specified"); if (errors.getFieldErrorCount("username") > 0) { return;/* w w w . j ava 2s . co m*/ } MutableUserDetails userDetails = (MutableUserDetails) userDetailsIn; if (!StringUtils.isAlphanumeric(userDetails.getUsername())) { errors.rejectValue("username", "error.username.illegal-characters"); } if (userDetails.getUsername().length() > MAX_USERNAME_LENGTH) { errors.rejectValue("username", "error.username.too-long"); } if (errors.hasErrors()) userDetails.setPassword(""); }
From source file:org.apache.rave.portal.web.validator.WidgetValidator.java
/** * Checks if the required fields contain a value * * @param errors {@link Errors}/*from ww w . j a v a 2s . c o m*/ */ private void validateRequiredFields(Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "widget.title.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_URL, "widget.url.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "type", "widget.type.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "widget.description.required"); }