List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode);
From source file:de.hybris.platform.commerceorgaddon.controllers.pages.B2BUserGroupManagementPageController.java
@RequestMapping(value = "/edit", method = RequestMethod.POST) @RequireHardLogIn/*from ww w . j a v a 2s. c o m*/ public String editUserGroup(@RequestParam("usergroup") final String usergroup, @Valid final B2BUserGroupForm userGroupForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { storeCmsPageInModel(model, getContentPageForLabelOrId(MANAGE_USERGROUPS_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(MANAGE_USERGROUPS_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder .createManageUserGroupDetailsBreadCrumbs(usergroup); breadcrumbs.add(new Breadcrumb( String.format("/my-company/organization-management/manage-usergroups/edit?usergroup=%s", urlEncode(usergroup)), getMessageSource().getMessage("text.company.manageUsergroups.editUsergroup.breadcrumb", new Object[] { usergroup }, "Edit {0} Usergroup ", getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } if (!userGroupForm.getUid().equals(usergroup) && b2bUserGroupFacade.getB2BUserGroup(userGroupForm.getUid()) != null) { // a unit uid is not unique GlobalMessages.addErrorMessage(model, "form.global.error"); bindingResult.rejectValue("uid", "form.b2busergroup.notunique"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } final B2BUserGroupData userGroupData = b2bUserGroupFacade.getB2BUserGroup(usergroup); if (userGroupData != null) { boolean userGroupUpdated = false; userGroupData.setUid(userGroupForm.getUid()); userGroupData.setName(userGroupForm.getName()); if (StringUtils.isNotBlank(userGroupForm.getParentUnit())) { final B2BUnitData newUserGroup = b2bUnitFacade.getUnitForUid(userGroupForm.getParentUnit()); if (!newUserGroup.getUid().equals(userGroupData.getUnit().getUid())) { userGroupUpdated = true; } userGroupData.setUnit(newUserGroup); } b2bUserGroupFacade.updateUserGroup(userGroupForm.getOriginalUid(), userGroupData); if (userGroupUpdated) { GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.INFO_MESSAGES_HOLDER, "form.b2busergroup.parentunit.updated"); } else { GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "form.b2busergroup.success"); } return String.format(REDIRECT_TO_USERGROUP_DETAILS, urlEncode(userGroupForm.getUid())); } else { // user has no permissions to edit the group. GlobalMessages.addErrorMessage(model, "form.b2busergroup.noeditpermissions"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.B2BUserGroupManagementPageController.java
@RequestMapping(value = "/edit", method = RequestMethod.POST) @RequireHardLogIn/* www. j a v a 2s . c o m*/ public String editUserGroup(@RequestParam("usergroup") final String usergroup, @Valid final B2BUserGroupForm userGroupForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { storeCmsPageInModel(model, getContentPageForLabelOrId(MANAGE_USERGROUPS_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(MANAGE_USERGROUPS_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder .createManageUserGroupDetailsBreadCrumbs(usergroup); breadcrumbs.add(new Breadcrumb( String.format("/my-company/organization-management/manage-usergroups/edit?usergroup=%s", urlEncode(usergroup)), getMessageSource().getMessage("text.company.manageUsergroups.editUsergroup.breadcrumb", new Object[] { usergroup }, "Edit {0} Usergroup ", getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } if (!userGroupForm.getUid().equals(usergroup) && b2bCommerceB2BUserGroupFacade.getB2BUserGroup(userGroupForm.getUid()) != null) { // a unit uid is not unique GlobalMessages.addErrorMessage(model, "form.global.error"); bindingResult.rejectValue("uid", "form.b2busergroup.notunique"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } final B2BUserGroupData userGroupData = b2bCommerceB2BUserGroupFacade.getB2BUserGroup(usergroup); if (userGroupData != null) { boolean userGroupUpdated = false; userGroupData.setUid(userGroupForm.getUid()); userGroupData.setName(userGroupForm.getName()); if (StringUtils.isNotBlank(userGroupForm.getParentUnit())) { final B2BUnitData newUserGroup = companyB2BCommerceFacade .getUnitForUid(userGroupForm.getParentUnit()); if (!newUserGroup.getUid().equals(userGroupData.getUnit().getUid())) { userGroupUpdated = true; } userGroupData.setUnit(newUserGroup); } try { b2bCommerceB2BUserGroupFacade.updateUserGroup(userGroupForm.getOriginalUid(), userGroupData); } catch (final DuplicateUidException e) { GlobalMessages.addErrorMessage(model, "form.global.error"); bindingResult.rejectValue("uid", "form.b2busergroup.notunique"); return editUserGroup(usergroup, model); } if (userGroupUpdated) { GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.INFO_MESSAGES_HOLDER, "form.b2busergroup.parentunit.updated"); } else { GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "form.b2busergroup.success"); } return String.format(REDIRECT_TO_USERGROUP_DETAILS, urlEncode(userGroupForm.getUid())); } else { // user has no permissions to edit the group. GlobalMessages.addErrorMessage(model, "form.b2busergroup.noeditpermissions"); model.addAttribute(userGroupForm); return editUserGroup(usergroup, model); } }
From source file:com.epam.cme.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-profile", method = RequestMethod.POST) public String updateProfile(@Valid final UpdateProfileForm updateProfileForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage; final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final CustomerData customerData = new CustomerData(); customerData.setTitleCode(updateProfileForm.getTitleCode()); customerData.setFirstName(updateProfileForm.getFirstName()); customerData.setLastName(updateProfileForm.getLastName()); customerData.setUid(currentCustomerData.getUid()); customerData.setDisplayUid(currentCustomerData.getDisplayUid()); model.addAttribute("titleData", userFacade.getTitles()); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); } else {//from ww w . j a v a 2 s. co m try { customerFacade.updateProfile(customerData); redirectAttributes.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER, Collections.singletonList("text.account.profile.confirmationUpdated")); returnAction = REDIRECT_TO_PROFILE_PAGE; } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "registration.error.account.exists.title"); 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")); return returnAction; }
From source file:at.fh.swenga.firefighters.controller.FireFighterController.java
@RequestMapping(value = "newFireBrigadeUser", method = RequestMethod.POST) public ModelAndView newFireBrigadeUserUserAccount(@ModelAttribute("user") @Valid UserDto accountDto, BindingResult result, WebRequest request, Errors errors) { System.out.println(accountDto); accountDto.setFireBrigadeName(getSessionFireBrigade().getName()); accountDto.setFireBrigadeStreetName(getSessionFireBrigade().getStreetName()); accountDto.setFireBrigadeTown(getSessionFireBrigade().getPostTown()); accountDto.setFireBrigadePostalCode(getSessionFireBrigade().getPostalCode()); System.out.println(accountDto); System.out.println(result);/*from ww w.j av a2 s. c om*/ User registered = new User(); if (!result.hasErrors()) { registered = createAccount(accountDto, result); } if (registered == null) { result.rejectValue("email", "message.regError"); } if (result.hasErrors()) { return new ModelAndView("newFireBrigadeUser", "user", accountDto); } else { return new ModelAndView("successFireBrigadeUser", "user", accountDto); } }
From source file:de.otto.mongodb.profiler.web.CollectionProfileController.java
@Page(mainNavigation = MainNavigation.DATABASES) @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public ModelAndView addCollectionProfile( @Valid @ModelAttribute("collection") AddCollectionProfileFormModel model, final BindingResult bindingResult, @PathVariable("connectionId") final String connectionId, @PathVariable("databaseName") final String databaseName, final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException { final ProfiledDatabase database = requireDatabase(connectionId, databaseName); if (bindingResult.hasErrors()) { return showDatabasePageWith(model, database); }/*from w w w.ja va2 s . c o m*/ final CollectionProfiler collectionProfiler = getProfilerService().getCollectionProfiler(database); final String uri; if (Boolean.TRUE.equals(model.getAddAll())) { final Set<String> collections = collectionProfiler.getAvailableCollections(); for (String collection : collections) { try { collectionProfiler.addProfile(collection); } catch (CollectionDoesNotExistException e) { logger.debug(e, "Failed to add collection [%s]", collection); } } uri = uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}/collections") .buildAndExpand(connectionId, databaseName).toUriString(); } else { final CollectionProfile collectionProfile; try { collectionProfile = collectionProfiler.addProfile(model.getName()); } catch (CollectionDoesNotExistException e) { logger.debug(e, "Failed to add collection [%s]", model.getName()); bindingResult.rejectValue("name", "collectionDoesNotExist"); return showDatabasePageWith(model, database); } uri = uriComponentsBuilder .path("/connections/{connectionId}/databases/{databaseName}/collections/{collectionName}") .buildAndExpand(connectionId, databaseName, collectionProfile.getCollectionName()) .toUriString(); } return new ModelAndView(new RedirectView(uri)); }
From source file:com.acc.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-profile", method = RequestMethod.POST) @RequireHardLogIn/*from ww w .j a va 2s . com*/ public String updateProfile(final UpdateProfileForm updateProfileForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getProfileValidator().validate(updateProfileForm, bindingResult); String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage; final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final CustomerData customerData = new CustomerData(); customerData.setTitleCode(updateProfileForm.getTitleCode()); customerData.setFirstName(updateProfileForm.getFirstName()); customerData.setLastName(updateProfileForm.getLastName()); customerData.setUid(currentCustomerData.getUid()); customerData.setDisplayUid(currentCustomerData.getDisplayUid()); model.addAttribute("titleData", userFacade.getTitles()); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); } else { try { customerFacade.updateProfile(customerData); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); returnAction = REDIRECT_TO_PROFILE_PAGE; } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "registration.error.account.exists.title"); 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")); return returnAction; }
From source file:com.epam.trade.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-profile", method = RequestMethod.POST) public String updateProfile(final UpdateProfileForm updateProfileForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getProfileValidator().validate(updateProfileForm, bindingResult); String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage; final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final CustomerData customerData = new CustomerData(); customerData.setTitleCode(updateProfileForm.getTitleCode()); customerData.setFirstName(updateProfileForm.getFirstName()); customerData.setLastName(updateProfileForm.getLastName()); customerData.setUid(currentCustomerData.getUid()); customerData.setDisplayUid(currentCustomerData.getDisplayUid()); model.addAttribute("titleData", userFacade.getTitles()); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); } else {// ww w . j av a2 s. com try { customerFacade.updateProfile(customerData); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); returnAction = REDIRECT_TO_PROFILE_PAGE; } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "registration.error.account.exists.title"); 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")); return returnAction; }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/update-profile", method = RequestMethod.POST) @RequireHardLogIn//www. java 2 s. co m public String updateProfile(@Valid final UpdateProfileForm updateProfileForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage; final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final CustomerData customerData = new CustomerData(); customerData.setTitleCode(updateProfileForm.getTitleCode()); customerData.setFirstName(updateProfileForm.getFirstName()); customerData.setLastName(updateProfileForm.getLastName()); customerData.setUid(currentCustomerData.getUid()); customerData.setDisplayUid(currentCustomerData.getDisplayUid()); model.addAttribute("titleData", userFacade.getTitles()); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); } else { try { customerFacade.updateProfile(customerData); GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated"); returnAction = REDIRECT_TO_PROFILE_PAGE; } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "registration.error.account.exists.title"); 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")); return returnAction; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductBundlesController.java
/** * This method is used to edit the Product Bundle logo * // w ww. ja v a 2 s .c o m * @param form * @param result * @param request * @param map * @return */ @RequestMapping(value = ("/editlogo"), method = RequestMethod.POST) @ResponseBody public String editBundleLogo(@ModelAttribute("bundleLogoForm") ProductBundleLogoForm form, BindingResult result, HttpServletRequest request, ModelMap map) { logger.debug("### editBundleLogo method starting...(POST)"); String fileSize = checkFileUploadMaxSizeException(request); if (fileSize != null) { result.rejectValue("logo", "error.image.max.upload.size.exceeded"); JsonObject error = new JsonObject(); error.addProperty("errormessage", messageSource.getMessage(result.getFieldError("logo").getCode(), new Object[] { fileSize }, request.getLocale())); return error.toString(); } String rootImageDir = config.getValue(Names.com_citrix_cpbm_portal_settings_images_uploadPath); if (rootImageDir != null && !rootImageDir.trim().equals("")) { ProductBundle bundle = form.getBundle(); ProductBundleLogoFormValidator validator = new ProductBundleLogoFormValidator(); validator.validate(form, result); if (result.hasErrors()) { return messageSource.getMessage(result.getFieldError("logo").getCode(), null, request.getLocale()); } else { String bundlesDir = "productbundles"; File file = new File(FilenameUtils.concat(rootImageDir, bundlesDir)); if (!file.exists()) { file.mkdir(); } String bundlesAbsoluteDir = FilenameUtils.concat(rootImageDir, bundlesDir); String relativeImageDir = FilenameUtils.concat(bundlesDir, bundle.getId().toString()); File file1 = new File(FilenameUtils.concat(bundlesAbsoluteDir, bundle.getId().toString())); if (!file1.exists()) { file1.mkdir(); } MultipartFile logoFile = form.getLogo(); try { if (!logoFile.getOriginalFilename().trim().equals("")) { String logoFileRelativePath = writeMultiPartFileToLocalFile(rootImageDir, relativeImageDir, logoFile); bundle.setImagePath(logoFileRelativePath); } bundle = productBundleService.updateProductBundle(bundle, false); } catch (IOException e) { logger.debug("###IO Exception in writing custom image file"); result.rejectValue("logo", "error.uploading.file"); JsonObject error = new JsonObject(); error.addProperty("errormessage", messageSource .getMessage(result.getFieldError("logo").getCode(), null, request.getLocale())); return error.toString(); } } String response = null; try { response = JSONUtils.toJSONString(bundle); } catch (JsonGenerationException e) { logger.debug("###IO Exception in writing custom image file"); } catch (JsonMappingException e) { logger.debug("###IO Exception in writing custom image file"); } catch (IOException e) { logger.debug("###IO Exception in writing custom image file"); } return response; } else { result.rejectValue("logo", "error.custom.image.upload.dir"); JsonObject error = new JsonObject(); error.addProperty("errormessage", messageSource.getMessage(result.getFieldError("logo").getCode(), null, request.getLocale())); return error.toString(); } }