List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode, String defaultMessage);
From source file:com.rambird.web.OwnerController.java
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Model model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search }//from w w w . ja v a2 s . c o m // find owners by last name Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName()); if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } if (results.size() > 1) { // multiple owners found model.addAttribute("selections", results); return "owners/ownersList"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } }
From source file:com.rambird.miles.web.OwnerController.java
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Model model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search }//from www. j a v a 2 s. c o m // find owners by last name Collection<Owner> results = this.rambirdService.findOwnerByLastName(owner.getLastName()); if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } if (results.size() > 1) { // multiple owners found model.addAttribute("selections", results); return "owners/ownersList"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } }
From source file:ro.teamnet.hero.signup.SignupController.java
private Account createAccount(SignupForm form, BindingResult formBinding) { try {//from ww w . jav a 2 s . c o m Account account = new Account(); account.setUserName(form.getUsername()); account.setPassword(form.getPassword()); Person person = new Person(); person.setFirstName(form.getFirstName()); person.setLastName(form.getLastName()); account.setPerson(person); accountService.createAccount(account); return account; } catch (UsernameAlreadyInUseException e) { formBinding.rejectValue("username", "user.duplicateUsername", "already in use"); return null; } }
From source file:com.branded.holdings.qpc.web.OwnerController.java
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search }/*from www . j a v a 2 s. c om*/ // find owners by last name Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName()); if (results.isEmpty()) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } else { // multiple owners found model.put("selections", results); return "owners/ownersList"; } }
From source file:dochef.controller.SignupController.java
private User createUser(SignupForm form, BindingResult formBinding) { try {//w w w . j a v a 2 s . co m User user = userRepository.findByEmail(form.getUsername()); if (user != null) throw new UsernameAlreadyInUseException("El " + form.getUsername() + " ya esta registrado"); user = new User(form.getUsername(), form.getFirstName(), form.getLastName(), form.getPassword()); user.setRole(Role.ROLE_FREE); userRepository.save(user); return user; } catch (UsernameAlreadyInUseException e) { formBinding.rejectValue("username", "user.duplicateUsername", "already in use"); return null; } }
From source file:com.june.app.web.OwnerController.java
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search }/* w w w . j a v a2 s .c o m*/ // find owners by last name Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName()); if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } if (results.size() > 1) { // multiple owners found model.put("selections", results); return "owners/ownersList"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } }
From source file:com.pet.demo.web.OwnerController.java
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search }// w w w .j a va2s. c o m // find owners by last name Collection<Owner> results = this.petDemoService.findOwnerByLastName(owner.getLastName()); if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; } if (results.size() > 1) { // multiple owners found model.put("selections", results); return "owners/ownersList"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owners/" + owner.getId(); } }
From source file:io.pivotal.cla.mvc.admin.AdminCrudClaController.java
@RequestMapping(value = "/admin/cla", method = RequestMethod.POST) public String saveCla(@AuthenticationPrincipal User user, @Valid ClaForm claForm, BindingResult result, Map<String, Object> model) throws Exception { boolean primary = claForm.isPrimary(); if (primary) { ContributorLicenseAgreement existingPrimaryCla = claRepo.findByNameAndPrimaryTrue(claForm.getName()); Long existingPrimaryClaId = existingPrimaryCla == null ? null : existingPrimaryCla.getId(); if (existingPrimaryClaId != null && !existingPrimaryClaId.equals(claForm.getId())) { result.rejectValue("primary", "errors.primary.exists", "A primary CLA with this name already exists"); }// ww w .j ava 2 s . c o m } if (result.hasErrors()) { Iterable<ContributorLicenseAgreement> clas = claRepo.findAll(); model.put("licenses", clas); return "admin/cla/form"; } ContributorLicenseAgreement supersedingCla = null; if (claForm.getSupersedingCla() != null) { supersedingCla = claRepo.findOne(claForm.getSupersedingCla()); } String accessToken = user.getAccessToken(); MarkdownContent individual = claForm.getIndividualContent(); String individualHtml = gitHub.markdownToHtml(accessToken, individual.getMarkdown()); individual.setHtml(individualHtml); MarkdownContent corporate = claForm.getCorporateContent(); String corperateHtml = gitHub.markdownToHtml(accessToken, corporate.getMarkdown()); corporate.setHtml(corperateHtml); boolean isCreateNew = claForm.getId() == null; ContributorLicenseAgreement cla = isCreateNew ? new ContributorLicenseAgreement() : claRepo.findOne(claForm.getId()); cla.setCorporateContent(claForm.getCorporateContent()); cla.setDescription(claForm.getDescription()); cla.setIndividualContent(claForm.getIndividualContent()); cla.setName(claForm.getName()); cla.setPrimary(claForm.isPrimary()); cla.setSupersedingCla(supersedingCla); claRepo.save(cla); return "redirect:/admin/cla/?success"; }
From source file:com.spring.blueye.web.UserController.java
@RequestMapping(value = "/users", method = RequestMethod.GET) public String processFindForm(User user, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /owners to return all records if (user.getLastName() == null) { user.setLastName(""); // empty string signifies broadest possible search }//from w w w. j a va 2s . c o m // find owners by last name Collection<User> results = this.coreService.findUserByLastName(user.getLastName()); if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "users/findUsers"; } if (results.size() > 1) { // multiple owners found model.put("selections", results); return "users/usersList"; } else { // 1 user found user = results.iterator().next(); return "redirect:/users/" + user.getId(); } }
From source file:com.catt.mobile.web.AccountController.java
@RequestMapping(value = "/accounts", method = RequestMethod.GET) public String processFindForm(Account account, BindingResult result, Map<String, Object> model) { // allow parameterless GET request for /accounts to return all records if (account.getName() == null) { account.setName(""); // empty string signifies broadest possible // search }//from ww w.jav a 2 s. c o m // find accounts by last name Collection<Account> results = this.mobileService.findAccountByName(account.getName()); if (results.size() < 1) { // no accounts found result.rejectValue("lastName", "notFound", "not found"); return "accounts/findaccounts"; } if (results.size() > 1) { // multiple accounts found model.put("selections", results); return "accounts/accountsList"; } else { // 1 account found account = results.iterator().next(); return "redirect:/accounts/" + account.getId(); } }