List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, @Nullable Object[] errorArgs)
From source file:org.spirit.spring.validate.BotListEntityLinksValidator.java
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) *///from w w w.j av a2s . c o m public void validate(Object obj, Errors errors) { BotListEntityLinksForm form = (BotListEntityLinksForm) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "urlTitle", "required", "* Title Field is required."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mainUrl", "required", "* Please submit a URL or use 'self'."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "keywords", "required", "* Please enter keyword tags (space separated)."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "required", "* Please enter a valid username (e.g botrover20)."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userSolution", "required", "* Please add the following values."); if (form != null) { if (!KeywordProcessor.validateFilterAlphaNumeric(form.getFullName())) { errors.reject("fullName", "* Please enter a valid username (for example: botrover20)."); } } if ((form != null) && (form.getMainUrl() != null)) { String url = form.getMainUrl(); // If url does not equal self and is not a valid url, flag an error if (!url.equalsIgnoreCase("self") && !this.isValidUrl(url)) { errors.reject("mainUrl", "* Please enter a valid url address (for example: http://www.url.com) or use 'self'"); } } if ((form != null) && (form.getUserSolution() != null) && (form.getUserSolution() != null)) { if (form.getPrevSolution().intValue() != form.getUserSolution().intValue()) { errors.reject("userSolution", "* Please add the following values."); } } }
From source file:cdr.forms.DepositValidator.java
@Override public void validate(Object target, Errors errors) { Deposit deposit = (Deposit) target;/*from w w w . j a va2 s . c om*/ Form form = deposit.getForm(); // Validate receipt email address if (deposit.getReceiptEmailAddress() != null && deposit.getReceiptEmailAddress().trim().length() > 0) { try { InternetAddress address = new InternetAddress(deposit.getReceiptEmailAddress()); address.validate(); } catch (AddressException e) { errors.rejectValue("receiptEmailAddress", "invalidEmailAddress", "You must enter a valid email address."); } } // The main file is required if there are no FileBlock elements if (!form.isHasFileBlocks()) { if (deposit.getMainFile() == null) errors.rejectValue("mainFile", "file.required", "This file is required."); } // Validate the form int elementIndex = 0; for (DepositElement element : deposit.getElements()) { if (element.getFormElement() instanceof MetadataBlock) { int entryIndex = 0; MetadataBlock metadataBlock = (MetadataBlock) element.getFormElement(); for (DepositEntry entry : element.getEntries()) { int portIndex = 0; for (InputField<?> inputField : metadataBlock.getPorts()) { if (inputField instanceof EmailInputField) { String path = "elements[" + elementIndex + "].entries[" + entryIndex + "].fields[" + portIndex + "].value"; try { InternetAddress address = new InternetAddress((String) errors.getFieldValue(path)); address.validate(); } catch (AddressException e) { errors.rejectValue(path, "invalidEmailAddress", "You must enter a valid email address."); } } else if (inputField.isRequired()) { String path = "elements[" + elementIndex + "].entries[" + entryIndex + "].fields[" + portIndex + "].value"; ValidationUtils.rejectIfEmptyOrWhitespace(errors, path, "field.required", "This field is required."); } portIndex++; } entryIndex++; } } if (element.getFormElement() instanceof FileBlock) { int entryIndex = 0; FileBlock fileBlock = (FileBlock) element.getFormElement(); for (DepositEntry entry : element.getEntries()) { if (fileBlock.isRequired() && entry.getFile() == null) errors.rejectValue("elements[" + elementIndex + "].entries[" + entryIndex + "].file", "file.required", "This file is required."); entryIndex++; } } if (element.getFormElement() instanceof MajorBlock) { MajorBlock majorBlock = (MajorBlock) element.getFormElement(); if (majorBlock.getSelectedMajor() == null) { errors.rejectValue("elements[" + elementIndex + "]", "field.required", "This field is required."); } } elementIndex++; } }
From source file:com.iana.dver.controller.validators.RegistrationValidator.java
public void validateStep2(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverUserLoginVO.userName", "required.userName", "User Name can not be blank"); // unique User Name validation; if (errors.getFieldError("dverUserLoginVO.userName") == null && isUserNameExists(errors.getFieldValue("dverUserLoginVO.userName").toString())) { errors.rejectValue("dverUserLoginVO.userName", "username.nonunique", "The provided User Name already exists"); }//w w w.j a v a 2s .c om ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverUserLoginVO.password", "required.password", "Password can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverUserLoginVO.confirmPwd", "required.confirmPwd", "Repeat password can not be blank."); // check if both the passwords are equal or not. verifyPwdAndConfirmPwdEqual(errors, errors.getFieldValue("dverUserLoginVO.password").toString(), errors.getFieldValue("dverUserLoginVO.confirmPwd").toString()); }
From source file:com.iana.dver.controller.DverUserController.java
private void validateCompanyProfile(DverUserVO userVO, BindingResult errors) { try {// w w w .j ava 2 s .co m ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "required.firstName", "First Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "required.lastName", "Last Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.title", "Title can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "required.phone", "Phone can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fax", "required.fax", "Fax No. can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address1", "required.address1", "Address can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "required.city", "City can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "required.state", "State Code can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zipCode", "required.zipCode", "ZIP Code can not be blank."); } catch (Exception ex) { logger.error("Error in validateCompanyProfile()....." + ex); DVERUtil.sendExceptionEmails("validateCompanyProfile method of DverUserController \n " + ex); } }
From source file:com.iana.dver.controller.validators.RegistrationValidator.java
public void validateStep3(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverConfigVO.firstName", "required.firstName", "First Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverConfigVO.lastName", "required.lastName", "Last Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverConfigVO.title", "required.title", "Title can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverConfigVO.email", "required.email", "Email can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dverConfigVO.phone", "required.phone", "Phone can not be blank."); }
From source file:com.iana.dver.controller.DverUserController.java
private void validateDverConfig(DverConfigVO dverConfigVO, BindingResult errors) { try {// w w w . jav a 2s . com ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "required.firstName", "First Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "required.lastName", "Last Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required.email", "Email can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "required.phone", "Phone can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.title", "Title can not be blank."); } catch (Exception ex) { logger.error("Error in validateDverConfig()....." + ex); DVERUtil.sendExceptionEmails("validateDverConfig method of DverUserController \n " + ex); } }
From source file:com.iana.dver.controller.DverUserController.java
private void validateChangePwdForm(ChangePwdVO changePwdVO, BindingResult errors) { try {//from w ww .ja va 2 s . c o m ValidationUtils.rejectIfEmptyOrWhitespace(errors, "oldPwd", "required.oldPwd", "Current Password can not be left blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPwd", "required.newPwd", "New Password can not be left blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "reTypeNewPwd", "required.reTypeNewPwd", "Confirm New Password can not be left blank."); } catch (Exception ex) { DVERUtil.sendExceptionEmails("validateChangePwdForm method of DverUserController \n " + ex); logger.error("Error in validateChangePwdForm()....." + ex); } }
From source file:com.iana.dver.controller.DverAdminController.java
private void validateEditCompanyForAdmin(DverUserVO userVO, BindingResult errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "companyName", "required.companyName", "Company Name can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "scac", "required.scac", "SCAC can not be blank."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "usDOT", "required.usDOT", "US DOT can not be blank."); if (!errors.hasErrors()) { validateScacAndDot(userVO, errors); }/* ww w. ja v a 2s .c o m*/ }
From source file:de.iteratec.iteraplan.presentation.dialog.common.model.ReleaseNameComponentModel.java
public void validate(Errors errors) { Object[] params = IteraplanValidationUtils.getLocalizedArgsWithSpanTags("global.name", "errorInline"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "elementName.current", "errors.required", params); if (elementName.getCurrent().contains("#") || elementName.getCurrent().contains(":")) { errors.rejectValue("elementName.current", "errors.releasemask"); }/*w w w. j av a 2 s .c o m*/ if (releaseName.getCurrent().contains("#") || releaseName.getCurrent().contains(":")) { errors.rejectValue("releaseName.current", "errors.releasemask"); } if (releaseName.getCurrent().length() > Constants.TEXT_SHORT) { errors.rejectValue("releaseName.current", "NAME_TOO_LONG"); } if (elementName.getCurrent().length() > Constants.TEXT_SHORT) { errors.rejectValue("elementName.current", "NAME_TOO_LONG"); } }
From source file:edu.psu.citeseerx.myciteseer.domain.logic.AccountValidator.java
/** * Validates the username /*from w w w. j a v a2s .co m*/ * @param username Username to be validated * @param errors Contains any error that might occur */ public void validateUsername(String username, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "USERNAME_REQUIRED", "Username is required."); if (errors.getAllErrors().size() == 0) { try { Account existingAccount = myciteseer.getAccount(username); if (existingAccount != null) { errors.rejectValue("username", "USERNAME_UNIQUE_REQUIRED", "This user ID is already taken."); } } catch (Exception e) { /* ignore */ } } }