List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode, String defaultMessage);
From source file:com.greenline.guahao.web.module.home.controllers.mobile.patient.MobilePatientController.java
/** * html5 ??? post/*from w w w .j ava2 s.c o m*/ * * @param model * @param patient * @param result * @return String */ @MethodRemark(value = "remark=html ???method=post") @RequestMapping(value = MobileConstants.M_PAIENT_UPDATE_PATH, method = RequestMethod.POST) public String patientUpdate(ModelMap model, @ModelAttribute("patient") PatientInfoDO patient, BindingResult result) { // ?cookieuserId Long cuserId = UserCookieUtil.getUserId(request); boolean hasError = Boolean.FALSE; String decodeUserId = DESUtil.DESDecode(patient.getEncodeUserId(), EncodeKeyConstants.USER_ENCODE_KEY); if (StringUtils.isBlank(decodeUserId) || !decodeUserId.equals(cuserId.toString())) { hasError = Boolean.TRUE; result.rejectValue("user_id", "user_id.error", "?."); } // ?? PatientValidator validator = new PatientValidator(); validator.validate(patient, result); if (result.hasErrors()) { hasError = Boolean.TRUE; } if (!hasError) { patient.setPatient_cert_type(CertTypEnum.IDCARD.getValue()); patient.setPatient_birthday(com.greenline.guahao.web.module.common.utils.UserUtil .getBirthdayByCardno(patient.getPatient_cert_no())); patient.setPatient_sex(com.greenline.guahao.web.module.common.utils.UserUtil .getSexByCardno(patient.getPatient_cert_no())); patient.setUser_id(Long.valueOf(decodeUserId)); String decodePatientId = DESUtil.DESDecode(patient.getEncodePatientId(), EncodeKeyConstants.PATIENT_ENCODE_KEY); patient.setPatient_id(Long.valueOf(decodePatientId)); PatientResult pr = patientManager.updatePatient(patient); if (pr.isSystemError()) { // hasError = Boolean.TRUE; model.put("message", pr.getResponseDesc()); } else { model.put("title", MobileMsgConstants.M_PATIENT_UPDATE_SUC); model.put("toUrl", MobileConstants.M_PAIENT_LIST_PATH); model.put("toTitle", "?"); return MobileConstants.M_SUCCESS; } } model.put("redict", patientManager.getRelationDictDef()); model.put("hasError", hasError); model.put("patient", patient); return MobileConstants.M_PAIENT_INFO; }
From source file:com.ctc.storefront.controllers.pages.checkout.steps.SopPaymentResponseController.java
protected void processPaymentSubscriptionErrors(final BindingResult bindingResult, final Model model, final PaymentSubscriptionResultData paymentSubscriptionResultData) { if (paymentSubscriptionResultData.getErrors() != null && !paymentSubscriptionResultData.getErrors().isEmpty()) { GlobalMessages.addErrorMessage(model, "checkout.error.paymentethod.formentry.invalid"); // Add in specific errors for invalid fields for (final PaymentErrorField paymentErrorField : paymentSubscriptionResultData.getErrors().values()) { if (paymentErrorField.isMissing()) { bindingResult.rejectValue(paymentErrorField.getName(), "checkout.error.paymentethod.formentry.sop.missing." + paymentErrorField.getName(), "Please enter a value for this field"); }// w ww . j av a2 s . co m if (paymentErrorField.isInvalid()) { bindingResult.rejectValue(paymentErrorField.getName(), "checkout.error.paymentethod.formentry.sop.invalid." + paymentErrorField.getName(), "This value is invalid for this field"); } } } else if (paymentSubscriptionResultData.getDecision() != null && "error".equalsIgnoreCase(paymentSubscriptionResultData.getDecision())) { LOGGER.error( "Failed to create subscription. Error occurred while contacting external payment services."); GlobalMessages.addErrorMessage(model, "checkout.multi.paymentMethod.addPaymentDetails.generalError"); } }
From source file:org.home.petclinic2.controller.PetController.java
/** * Retrieves all owners or allows for last name search * //from w ww .j a v a 2 s . co m * @param owner * @param result * @param model * @return */ @RequestMapping(value = "/pet", method = RequestMethod.GET) public String processFindForm(Pet pet, BindingResult result, Model model) { // allow parameterless GET request for /pet to return all records Collection<Pet> results = null; if (StringUtils.isEmpty(pet.getName())) { // find all pets results = clinicService.findAllPets(); } else { // find owners by last name results = clinicService.findPetByName(pet.getName()); } if (results == null) { throw new IllegalStateException("Results were null. This should not happen"); } else if (results.size() < 1) { // no pets found result.rejectValue("name", "notFound", "not found"); return "pet/findPet"; } else if (results.size() > 1) { // multiple pets found // here we've specified how we want to reference the model object model.addAttribute("selections", results); return "pet/pets"; } else { // 1 pet found pet = results.iterator().next(); return "redirect:/pet/" + pet.getId(); } }
From source file:org.easit.core.controllers.signup.SignupController.java
@RequestMapping(value = "/signup", method = RequestMethod.POST) public String signup(@Valid SignupForm form, BindingResult formBinding, WebRequest request, HttpServletRequest requestHttp, HttpServletResponse responseHttp) { try {//from w ww. j av a 2s . c o m if (formBinding.hasErrors()) return "signup"; EasitAccount account; account = createAccount(form, formBinding); if (account != null) { Authentication auth = SignInUtils.signin(account.getUsername()); ProviderSignInUtils.handlePostSignUp(account.getUsername(), request); loginSuccess.onAuthenticationSuccess(requestHttp, responseHttp, auth); } return "home"; } catch (UsernameAlreadyInUseException ex) { formBinding.rejectValue("username", "user.duplicateUsername", "already in use"); new UsernameAlreadyInUseException(form.getUsername()); return "signup"; } catch (Exception ex1) { logger.error(ex1.getMessage()); return "signup"; } }
From source file:sample.contact.web.AdminPermissionController.java
/** * Handles submission of the "add permission" form. *///from www .ja va2 s. c om @RequestMapping(value = "/secure/addPermission.htm", method = RequestMethod.POST) public String addPermission(AddPermission addPermission, BindingResult result, ModelMap model) { addPermissionValidator.validate(addPermission, result); if (result.hasErrors()) { model.put("recipients", listRecipients()); model.put("permissions", listPermissions()); return "addPermission"; } PrincipalSid sid = new PrincipalSid(addPermission.getRecipient()); Permission permission = permissionFactory.buildFromMask(addPermission.getPermission()); try { contactService.addPermission(addPermission.getContact(), sid, permission); } catch (DataAccessException existingPermission) { existingPermission.printStackTrace(); result.rejectValue("recipient", "err.recipientExistsForContact", "Addition failure."); model.put("recipients", listRecipients()); model.put("permissions", listPermissions()); return "addPermission"; } return "redirect:/secure/index.htm"; }
From source file:com.ai.bss.webui.party.controller.PartyController.java
@RequestMapping(value = "/createLegal", method = RequestMethod.POST) public String createLegal(@ModelAttribute("legal") @Valid Legal legal, BindingResult bindingResult, Model model) {/*from w w w . ja v a2 s . co m*/ if (!bindingResult.hasErrors()) { PartyId partyId = new PartyId(); CreateLegalCommand command = new CreateLegalCommand(partyId, legal.getLegalName()); command.setTenantId(TenantContext.getCurrentTenant()); try { command = client.postForObject("http://party-service/party/createLegalCommand", command, CreateLegalCommand.class); } catch (Exception e) { bindingResult.rejectValue("legalName", "error.createLegal.failed", e.getCause().getMessage()); } return "redirect:/party"; } return "createLegal"; }
From source file:com.iana.dver.controller.DverUserController.java
@RequestMapping(value = { "/admin/changepwd", "/iep/changepwd", "/mc/changepwd" }, method = RequestMethod.POST) public String submitChangePwd(HttpServletRequest request, HttpServletResponse response, final RedirectAttributes redirectAttributes, @ModelAttribute("changePwdVO") ChangePwdVO changePwdVO, BindingResult result) { try {/* w ww . ja v a 2s .com*/ logger.info("Submit Change Password Page..."); validateChangePwdForm(changePwdVO, result); if (!result.hasErrors()) { if (changePwdVO.getOldPwd().equals(changePwdVO.getNewPwd())) { result.rejectValue("newPwd", "same.pwd", "Current password and New Password can not be same."); return "change-pass"; } if (!result.hasErrors() && !changePwdVO.getNewPwd().equals(changePwdVO.getReTypeNewPwd())) { result.rejectValue("reTypeNewPwd", "pwd.not.similar", "New Password and Confirm Password can not be different."); return "change-pass"; } Boolean isValidOldPwd = this.dverUserService.verifyWithOldPassword(changePwdVO.getUserId(), changePwdVO.getOldPwd()); if (!isValidOldPwd) { result.rejectValue("oldPwd", "wrong.old.pwd", "Please enter correct Current Password."); return "change-pass"; } if (!result.hasErrors()) { this.dverUserService.changePassword(changePwdVO); if (this.securityObj != null) { request.getSession().removeAttribute("securityObj"); } DverUserVO userVO = this.dverUserService.getUserById(securityObj.getUserid()); DverConfigVO configVO = this.dverUserService.getDverConfigById(securityObj.getUserid()); sendChangePwdEmail(userVO, configVO, changePwdVO.getNewPwd()); redirectAttributes.addFlashAttribute("successMsg", "Password updated successfully."); return "redirect:/login"; } } else { return "change-pass"; } return "redirect:/login"; } catch (Exception ex) { DVERUtil.sendExceptionEmails("submitChangePwd method of DverUserController \n " + ex); logger.error("Error in submitChangePwd()....." + ex); return "error"; } }
From source file:com.ai.bss.webui.party.controller.PartyController.java
@RequestMapping(value = "/createIndividual", method = RequestMethod.POST) public String createIndividual(@ModelAttribute("individual") @Valid Individual individual, BindingResult bindingResult, Model model) { if (!bindingResult.hasErrors()) { PartyId partyId = new PartyId(); CreateIndividualCommand command = new CreateIndividualCommand(partyId, individual.getFirstName(), individual.getLastName()); command.setTenantId(TenantContext.getCurrentTenant()); try {/*from w ww. ja va 2 s.c o m*/ command = client.postForObject("http://party-service/party/createIndividualCommand", command, CreateIndividualCommand.class); } catch (Exception e) { bindingResult.rejectValue("firstName", "error.createIndividual.failed", e.getCause().getMessage()); } return "redirect:/party"; } return "createIndividual"; }
From source file:org.duracloud.account.app.controller.AccountGroupsController.java
@RequestMapping(value = GROUPS_PATH, method = RequestMethod.POST) @Transactional/*from w w w. j a v a 2 s . co m*/ public String modifyGroups(@PathVariable Long accountId, Model model, @ModelAttribute(GROUPS_FORM_KEY) @Valid GroupsForm form, BindingResult result) throws Exception { AccountService as = this.accountManagerService.getAccount(accountId); GroupsForm.Action action = form.getAction(); if (action == Action.ADD) { String name = form.getGroupName(); String groupName = DuracloudGroup.PREFIX + name; try { duracloudGroupService.createGroup(groupName, accountId); } catch (InvalidGroupNameException e) { if (groupName.equalsIgnoreCase(DuracloudGroup.PUBLIC_GROUP_NAME)) { result.rejectValue(GROUP_NAME_KEY, GROUP_NAME_RESERVED_ERROR_CODE, GROUP_NAME_RESERVED_MESSAGE); } else { result.rejectValue(GROUP_NAME_KEY, GROUP_NAME_INVALID_ERROR_CODE, GROUP_NAME_INVALID_MESSAGE); } } catch (DuracloudGroupAlreadyExistsException e) { result.rejectValue(GROUP_NAME_KEY, GROUP_NAME_EXISTS_ERROR_CODE, GROUP_NAME_EXISTS_MESSAGE); } if (!result.hasFieldErrors()) { return formatGroupRedirect(accountId, groupName, "/edit"); } } else { String[] groups = form.getGroupNames(); if (groups != null) { for (String name : groups) { DuracloudGroup group = duracloudGroupService.getGroup(name, accountId); removeGroup(group, accountId); } } } addGroupsObjectsToModel(as, model); return GROUPS_VIEW_ID; }
From source file:org.home.petclinic2.controller.OwnerController.java
/** * Retrieves all owners or allows for last name search * /*w ww . ja v a 2s . c om*/ * @param owner * @param result * @param model * @return */ // be careful where you place the BindingResult, there are some rules about // where it must fall in the method signature. Typically, I place all of the // validated beans at the beginning and then follow each bean being // validated with the binding result @RequestMapping(value = "/owner", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Model model) { // allow parameterless GET request for /owner to return all records Collection<Owner> results = null; if (StringUtils.isEmpty(owner.getLastName())) { // find all owners results = clinicService.findAllOwners(); } else { // find owners by last name results = clinicService.findOwnerByLastName(owner.getLastName()); } // ensure that we received results, otherwise we have an issue on our // hands if (results == null) { throw new IllegalStateException("Results were null. This should not happen"); } else if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owner/findOwner"; } else if (results.size() > 1) { // multiple owners found // here we've specified how we want to reference the model object model.addAttribute("selections", results); return "owner/owners"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owner/" + owner.getId(); } }