List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:edu.wisc.my.portlets.bookmarks.domain.validation.BookmarkValidator.java
private void validateUrl(Bookmark bookmark, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "url", "portlet.bookmark.error.url.required"); String url = bookmark.getUrl(); if (!url.contains(PROTOCOL_SEPERATOR)) { url = this.defaultProtocol + url; }/*w ww. j av a 2s . co m*/ bookmark.setUrl(url); try { new URL(url); } catch (MalformedURLException mue) { errors.rejectValue("url", "portlet.bookmark.error.url.malformed"); } }
From source file:com.virtusa.akura.common.validator.AssignmentValidator.java
/** * The actual Assignment Validate method validates to make sure that the assignment Object passed is null * or empty.//from w ww. jav a 2s . c o m * * @param target - the target object pass in for validation. * @param errors - contextual state about the validation process */ @Override public void validate(Object target, Errors errors) { Assignment assignments = (Assignment) target; if (assignments.getName().equals(STRING_NULL) || assignments.getDate() == null || assignments.getGradeDescription().equals(VAR_STRING)) { errors.rejectValue(ATTRIBUTE_GRADE_DESCRIPTION, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); } else { // remove white space in assignments ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME, REF_UI_ASSIGNMENT_DESCRIPTION_REQUIRED); } String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFERENCE.ASSIGNMENT.VALIDATOR"); Pattern stringPattern = Pattern.compile(validatorPattern); Matcher makeMatch = stringPattern.matcher(assignments.getName()); if (makeMatch.find()) { errors.rejectValue(FIELD_NAME, AkuraWebConstant.MISMATCH_ERROR); } }
From source file:alfio.util.Validator.java
public static ValidationResult validateEventPrices(Optional<Event> event, EventModification ev, Errors errors) { if (!isInternal(event, ev)) { return ValidationResult.success(); }//from ww w . ja v a 2 s. co m if (!ev.isFreeOfCharge()) { if (isCollectionEmpty(ev.getAllowedPaymentProxies())) { errors.rejectValue("allowedPaymentProxies", "error.allowedpaymentproxies"); } if (ev.getRegularPrice() == null || BigDecimal.ZERO.compareTo(ev.getRegularPrice()) >= 0) { errors.rejectValue("regularPrice", "error.regularprice"); } if (ev.getVatPercentage() == null || BigDecimal.ZERO.compareTo(ev.getVatPercentage()) > 0) { errors.rejectValue("vat", "error.vat"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "currency", "error.currency"); } if (ev.getAvailableSeats() < 1) { errors.rejectValue("availableSeats", "error.availableseats"); } return evaluateValidationResult(errors); }
From source file:com.ccserver.digital.validator.CreditCardApplicationValidator.java
private void validatePersonalTab(CreditCardApplicationDTO creditCardApplicationDTO, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "education", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "maritalStatus", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "permanentAddress", ErrorCodes.FIELD_REQUIRED); if (!creditCardApplicationDTO.isCurrentIsPermanent()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "currentAddress", ErrorCodes.FIELD_REQUIRED); }/*from w w w. j a va 2 s . c o m*/ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "monthsOfLiving", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "yearsOfLiving", ErrorCodes.FIELD_REQUIRED); }
From source file:com.google.ie.common.validation.CommentValidator.java
public void validateProjectComments(Object object, Errors errors) { ProjectComment projectComment = (ProjectComment) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, PROJECT_KEY, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, TEXT, IdeaExchangeConstants.Messages.REQUIRED_FIELD); if (StringUtils.length(projectComment.getText()) > COMMENT_LENGTH) { errors.rejectValue(TEXT, IdeaExchangeErrorCodes.COMMENT_LENGTH_EXCEEDS, IdeaExchangeConstants.Messages.COMMENT_LENGTH_EXCEEDS); }//from w w w .jav a2s. c o m if (log.isDebugEnabled()) { if (errors.hasErrors()) { log.debug("Validator found " + errors.getErrorCount() + " errors"); for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) { FieldError fieldError = iterator.next(); log.debug("Error found in field: " + fieldError.getField() + " Message :" + fieldError.getDefaultMessage()); } } else { log.debug("Validator found no errors"); } } }
From source file:com.cws.us.pws.validators.EmailAddressValidator.java
@Override public final void validate(final Object target, final Errors errors) { final String methodName = EmailAddressValidator.CNAME + "#validate(final <Class> request)"; if (DEBUG) {//from ww w. j a v a 2 s . c o m DEBUGGER.debug(methodName); DEBUGGER.debug("target: {}", target); DEBUGGER.debug("errors: {}", errors); } final EmailMessage message = (EmailMessage) target; final Pattern pattern = Pattern.compile( "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"); if (DEBUG) { DEBUGGER.debug("EmailMessage: {}", message); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddr", this.messageEmailAddressRequired); for (String str : message.getEmailAddr()) { if (DEBUG) { DEBUGGER.debug("Address: {}", str); } if (!(pattern.matcher(str).matches())) { errors.reject("emailAddr", this.messageEmailAddressRequired); } } }
From source file:org.openmrs.module.register.web.controller.RegisterFormController.java
private void validate(Register register, BindingResult errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "map['register'].name", "error.null"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "map['register'].registerType", "error.null"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "map['register'].htmlForm", "error.null"); if (register.getRetired()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "map['register'].retireReason", "error.null"); }//from ww w. j av a2s.co m }
From source file:com.cws.us.pws.validators.EmailMessageValidator.java
@Override public final void validate(final Object target, final Errors errors) { final String methodName = EmailMessageValidator.CNAME + "#validate(final Object target, final Errors errors)"; if (DEBUG) {//from ww w . j ava 2s . com DEBUGGER.debug(methodName); DEBUGGER.debug("Object: {}", target); DEBUGGER.debug("Errors: {}", errors); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "messageBody", this.messageBodyRequired); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddr", this.messageFromRequired); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "messageSubject", this.messageSubjectRequired); }
From source file:org.openmrs.module.diabetesmanagement.web.controller.InsulinTypeFormController.java
/** * The onSubmit method receives the form/command object that was modified by the input form and * saves it to the database./* w w w .j a va 2 s . c o m*/ * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) * @param request Current servlet request. * @param response Current servlet response. * @param command Form object with request parameters bound onto it. * @param errors Holder without errors. * @return The prepared model and view, or null. * @throws Exception In case of errors. */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { InsulinType type = (InsulinType) command; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.null"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parameterS", "error.null"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parameterA", "error.null"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parameterB", "error.null"); ((InsulinTypeService) Context.getService(InsulinTypeService.class)).saveInsulinType(type); view = getSuccessView(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "diabetesmanagement.insulinType.saved"); } return new ModelAndView(new RedirectView(view)); }
From source file:it.cilea.osd.jdyna.validator.ClassificazioneValidator.java
public void validateNome(Object object, Errors errors) { DTOGestioneAlberoClassificatore classificazione = (DTOGestioneAlberoClassificatore) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nome", "error.albero.nome.non.inserito"); if (classificazione.getNome() != "") { ValidationResult result = ((IValidatorClassificationService) getValidatorService()) .validaNomeAlberoInModifica(classificazione.getNome(), classificazione.getId(), errors); if (!result.isSuccess()) { errors.rejectValue("nome", "error.albero.nome.esistente"); }//from w ww. ja v a 2 s. co m } }