List of usage examples for org.springframework.validation FieldError FieldError
public FieldError(String objectName, String field, @Nullable Object rejectedValue, boolean bindingFailure, @Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage)
From source file:org.opentestsystem.delivery.testreg.upload.validator.fileformat.FileFormatValidator.java
private boolean processConstraintViolations(final FileDataRecord record, final Set<ConstraintViolation<TestRegistrationBase>> violations, final BindingResult errors) { boolean hasErrors = false; for (ConstraintViolation<TestRegistrationBase> violation : violations) { errors.addError(new FieldError(getDatasetName(), getFieldLabel(violation.getLeafBean(), getPropertyName(violation)), getInvalidValue(violation), false, null, new Object[] { record.getRowMetadata() }, violation.getMessage())); hasErrors = true;/*from www . java 2 s .c o m*/ } return hasErrors; }
From source file:org.orcid.frontend.web.controllers.BaseController.java
protected void validateEmailAddress(String email, boolean ignoreCurrentUser, boolean isRegisterRequest, HttpServletRequest request, BindingResult bindingResult) { if (StringUtils.isNotBlank(email)) { if (!validateEmailAddress(email)) { String[] codes = { "Email.personalInfoForm.email" }; String[] args = { email }; bindingResult.addError(new FieldError("email", "email", email, false, codes, args, "Not vaild")); }/*from www . j a v a2s . c om*/ if (!(ignoreCurrentUser && emailMatchesCurrentUser(email)) && emailManager.emailExists(email)) { OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfileByEmail(email); if (orcidProfile.getOrcidHistory().isClaimed()) { String[] codes = null; if (isRegisterRequest) { codes = new String[] { "orcid.frontend.verify.duplicate_email" }; } else { codes = new String[] { "orcid.frontend.verify.claimed_email" }; } String[] args = { email }; bindingResult.addError( new FieldError("email", "email", email, false, codes, args, "Email already exists")); } else { String resendUrl = createResendClaimUrl(email, request); String[] codes = { "orcid.frontend.verify.unclaimed_email" }; String[] args = { email, resendUrl }; bindingResult.addError( new FieldError("email", "email", email, false, codes, args, "Unclaimed record exists")); } } } }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
@RequestMapping(value = "/reset-password", method = RequestMethod.POST) public ModelAndView issuePasswordResetRequest(HttpServletRequest request, @ModelAttribute @Valid EmailAddressForm resetPasswordForm, BindingResult bindingResult) { String submittedEmail = resetPasswordForm.getUserEmailAddress(); ModelAndView mav = new ModelAndView("reset_password"); // if the email doesn't exist, or any other form errors.. don't bother // hitting db if (bindingResult.hasErrors()) { mav.addAllObjects(bindingResult.getModel()); return mav; }/*from w ww . j a v a 2s . c o m*/ OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(submittedEmail, LoadOptions.BIO_ONLY); // if the email can't be found on the system, then add to errors if (profile == null) { String[] codes = { "orcid.frontend.reset.password.email_not_found" }; String[] args = { submittedEmail }; bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", submittedEmail, false, codes, args, "Email not found")); mav.addAllObjects(bindingResult.getModel()); return mav; } else { if (profile.isDeactivated()) { mav.addObject("disabledAccount", true); return mav; } else { registrationManager.resetUserPassword(submittedEmail, profile); mav.addObject("passwordResetSuccessful", true); return mav; } } }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
@RequestMapping(value = "/resend-claim", method = RequestMethod.POST) public ModelAndView resendClaimEmail(HttpServletRequest request, @ModelAttribute @Valid EmailAddressForm emailAddressForm, BindingResult bindingResult) { String userEmailAddress = emailAddressForm.getUserEmailAddress(); ModelAndView mav = new ModelAndView("resend_claim"); // if the email doesn't exist, or any other form errors.. don't bother // hitting db if (bindingResult.hasErrors()) { mav.addAllObjects(bindingResult.getModel()); return mav; }/*from w w w. j av a2s. c o m*/ OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(userEmailAddress); // if the email can't be found on the system, then add to errors if (profile == null) { String[] codes = { "orcid.frontend.reset.password.email_not_found" }; String[] args = { userEmailAddress }; bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", userEmailAddress, false, codes, args, "Email not found")); mav.addAllObjects(bindingResult.getModel()); return mav; } else { if (profile.getOrcidHistory() != null && profile.getOrcidHistory().isClaimed()) { mav.addObject("alreadyClaimed", true); return mav; } else { notificationManager.sendApiRecordCreationEmail(userEmailAddress, profile); mav.addObject("claimResendSuccessful", true); return mav; } } }
From source file:org.springframework.validation.SimpleErrors.java
@Override public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) { FieldError err = new FieldError(getObjectName(), field, null, false, new String[] { errorCode }, errorArgs, defaultMessage);/*from ww w . j a v a 2 s .c o m*/ fieldErrors.add(err); }