List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs,
@Nullable String defaultMessage);
From source file:com.acc.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) @RequireHardLogIn/*from w ww . ja va 2s . c om*/ public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getEmailValidator().validate(updateEmailForm, bindingResult); String returnAction = REDIRECT_TO_PROFILE_PAGE; if (!bindingResult.hasErrors() && !updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); } if (bindingResult.hasErrors()) { returnAction = errorUpdatingEmail(model); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = errorUpdatingEmail(model); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("password", "profile.currentPassword.invalid"); returnAction = errorUpdatingEmail(model); } } return returnAction; }
From source file:com.ctc.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) @RequireHardLogIn/*from w w w. jav a2 s. com*/ public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getEmailValidator().validate(updateEmailForm, bindingResult); String returnAction = REDIRECT_TO_UPDATE_EMAIL_PAGE; if (!bindingResult.hasErrors() && !updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); } if (bindingResult.hasErrors()) { returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("password", PROFILE_CURRENT_PASSWORD_INVALID); returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } } return returnAction; }
From source file:whitelabel.cloud.webapp.impl.controller.CloudServersController.java
private void validateHDxx(CloudServer cloudServer, DiskSize diskSize, BindingResult bindingResult) { if (diskSize != null && cloudServer != null) { try {//from ww w .j a v a 2s .c om ResourceBound hdxBound = cloudServer.getAppHDxBound().get(diskSize.getDiskNum()); if (hdxBound != null) { if (diskSize.getSize() != null && hdxBound.getMin() != null) { boolean showError = false; if (diskSize.getSize() % hdxBound.getMin() != 0) { showError = true; } if (diskSize.getSize() < hdxBound.getMin() || diskSize.getSize() > hdxBound.getMax()) { showError = true; } if (showError) { bindingResult.rejectValue(null, "cloudServer.hdx.bad.size", new Object[] { diskSize.getDiskNum(), hdxBound.getMin(), hdxBound.getMax() }, ""); } } } } catch (Exception dontCare) { } } }
From source file:cec.easyshop.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) @RequireHardLogIn/*w ww. j a v a2s . c o m*/ public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getEmailValidator().validate(updateEmailForm, bindingResult); String returnAction = REDIRECT_TO_UPDATE_EMAIL_PAGE; if (!bindingResult.hasErrors() && !updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); } if (bindingResult.hasErrors()) { returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("password", "profile.currentPassword.invalid"); returnAction = setErrorMessagesAndCMSPage(model, UPDATE_EMAIL_CMS_PAGE); } } return returnAction; }
From source file:com.epam.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) @RequireHardLogIn/* w w w.j a v a2 s. co m*/ public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes, final HttpServletRequest request) throws CMSItemNotFoundException { getEmailValidator().validate(updateEmailForm, bindingResult); String returnAction = REDIRECT_TO_PROFILE_PAGE; if (!bindingResult.hasErrors() && !updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); } if (bindingResult.hasErrors()) { returnAction = errorUpdatingEmail(model); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = errorUpdatingEmail(model); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("password", "profile.currentPassword.invalid"); returnAction = errorUpdatingEmail(model); } } return returnAction; }
From source file:com.epam.trade.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes, final HttpServletRequest request) throws CMSItemNotFoundException { getEmailValidator().validate(updateEmailForm, bindingResult); String returnAction = REDIRECT_TO_PROFILE_PAGE; if (!bindingResult.hasErrors() && !updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); }/* w w w . ja v a2 s .c o m*/ if (bindingResult.hasErrors()) { returnAction = errorUpdatingEmail(model); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = errorUpdatingEmail(model); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("password", "profile.currentPassword.invalid"); returnAction = errorUpdatingEmail(model); } } return returnAction; }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-email", method = RequestMethod.POST) @RequireHardLogIn/*from www . ja va2s.c om*/ public String updateEmail(@Valid final UpdateEmailForm updateEmailForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { String returnAction = REDIRECT_TO_PROFILE_PAGE; if (!updateEmailForm.getEmail().equals(updateEmailForm.getChkEmail())) { bindingResult.rejectValue("chkEmail", "validation.checkEmail.equals", new Object[] {}, "validation.checkEmail.equals"); } if (bindingResult.hasErrors()) { returnAction = errorUpdatingEmail(model); } else { try { customerFacade.changeUid(updateEmailForm.getEmail(), updateEmailForm.getPassword()); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated"); // Replace the spring security authentication with the new UID final String newUid = customerFacade.getCurrentCustomer().getUid().toLowerCase(); final Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication(); final UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( newUid, null, oldAuthentication.getAuthorities()); newAuthentication.setDetails(oldAuthentication.getDetails()); SecurityContextHolder.getContext().setAuthentication(newAuthentication); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "profile.email.unique"); returnAction = errorUpdatingEmail(model); } catch (final PasswordMismatchException passwordMismatchException) { bindingResult.rejectValue("email", "profile.currentPassword.invalid"); returnAction = errorUpdatingEmail(model); } } return returnAction; }
From source file:com.acc.storefront.controllers.pages.CSRLoginPageController.java
@RequestMapping(value = "/csrLogin", method = RequestMethod.POST) public String csrLogin(final CsrLoginForm form, final Model model, final BindingResult bindingResult) throws CMSItemNotFoundException { String returnAction = ControllerConstants.Views.Pages.Account.csrLoginPage; try {/*from w ww . java2s.c o m*/ final PointOfServiceModel tempPointOfService = new PointOfServiceModel(); tempPointOfService.setName(form.getPos()); final PointOfServiceModel pointOfServiceModel = flexibleSearchService .getModelByExample(tempPointOfService); System.out.println("Point of service [ " + pointOfServiceModel + " ]."); final UserModel userModel = userService.getUserForUID(form.getUsername()); final UserGroupModel userGroupModel = userService.getUserGroupForUID("csrGroup"); if ((null != userGroupModel) && (userService.isMemberOfGroup(userModel, userGroupModel))) { final String pwd = userService.getPassword(userModel); if (null != pwd && pwd.equals(form.getPassword())) { sessionService.setAttribute("POINT_OF_SERVICE", form.getPos()); sessionService.setAttribute("CSR_USER", form.getUsername()); return REDIRECT_TO_CUSTOMER_DETAILS; } else { bindingResult.rejectValue("password", "login.error.account.not.found.title", new Object[] {}, "login.error.account.not.found.title"); } } else { bindingResult.rejectValue("username", "login.error.group.not.found", new Object[] {}, "login.error.group.not.found"); } } catch (final UnknownIdentifierException e) { bindingResult.rejectValue("username", "login.error.user.not.found", new Object[] {}, "login.error.user.not.found"); } catch (final ModelNotFoundException e) { bindingResult.rejectValue("pos", "login.error.pos.not.found", new Object[] {}, "login.error.pos.not.found"); } if (bindingResult.hasErrors()) { returnAction = csrPageError(model); } else { storeCmsPageInModel(model, getContentPageForLabelOrId(ACCOUNT_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ACCOUNT_CMS_PAGE)); } model.addAttribute("csrLoginForm", form); return returnAction; }
From source file:com.acc.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-password", method = RequestMethod.POST) @RequireHardLogIn//from www. j a v a2s .com public String updatePassword(final UpdatePasswordForm updatePasswordForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getPasswordValidator().validate(updatePasswordForm, bindingResult); if (!bindingResult.hasErrors()) { if (updatePasswordForm.getNewPassword().equals(updatePasswordForm.getCheckNewPassword())) { try { customerFacade.changePassword(updatePasswordForm.getCurrentPassword(), updatePasswordForm.getNewPassword()); } catch (final PasswordMismatchException localException) { bindingResult.rejectValue("currentPassword", "profile.currentPassword.invalid", new Object[] {}, "profile.currentPassword.invalid"); } } else { bindingResult.rejectValue("checkNewPassword", "validation.checkPwd.equals", new Object[] {}, "validation.checkPwd.equals"); } } if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); model.addAttribute("breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile.updatePasswordForm")); return ControllerConstants.Views.Pages.Account.AccountChangePasswordPage; } else { GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.confirmation.password.updated", null); return REDIRECT_TO_PROFILE_PAGE; } }
From source file:com.epam.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-password", method = RequestMethod.POST) @RequireHardLogIn// w w w. j ava2 s . c o m public String updatePassword(final UpdatePasswordForm updatePasswordForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getPasswordValidator().validate(updatePasswordForm, bindingResult); if (!bindingResult.hasErrors()) { if (updatePasswordForm.getNewPassword().equals(updatePasswordForm.getCheckNewPassword())) { try { customerFacade.changePassword(updatePasswordForm.getCurrentPassword(), updatePasswordForm.getNewPassword()); } catch (final PasswordMismatchException localException) { bindingResult.rejectValue("currentPassword", "profile.currentPassword.invalid", new Object[] {}, "profile.currentPassword.invalid"); } } else { bindingResult.rejectValue("checkNewPassword", "validation.checkPwd.equals", new Object[] {}, "validation.checkPwd.equals"); } } if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE)); model.addAttribute("breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile.updatePasswordForm")); return getViewForPage(model); } else { GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.confirmation.password.updated", null); return REDIRECT_TO_PROFILE_PAGE; } }