/** * Performs search. * * @param owner * @param bindingResult * @param model * @return view name */ @RequestMapping(value = "/search", method = RequestMethod.GET) public String search( @ModelAttribute("owner") Owner owner, BindingResult bindingResult, Model model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { owner.setLastName(""); // empty string signifies broadest possible search } String viewName; // find owners by last name Collection<Owner> owners = this.clinic.findOwners(owner.getLastName()); if (owners.size() < 1) { // no owners found bindingResult.rejectValue("lastName", "notFound", "not found"); viewName = "owner/SearchForm"; } else if (owners.size() > 1) { // multiple owners found model.addAttribute("owners", owners); viewName = "owner/SearchResults"; } else { // 1 owner found owner = owners.iterator().next(); viewName = "redirect:/owner/" + owner.getId(); } model.addAttribute( "allErrors", BindingResultUtils.getErrorMessages(bindingResult, messageSource)); return viewName; }
/** Saves form data. */ @RequestMapping(value = "/save", method = RequestMethod.POST) public String save( @ModelAttribute("owner") Owner owner, BindingResult bindingResult, Model model) { new OwnerValidator().validate(owner, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute( "allErrors", BindingResultUtils.getErrorMessages(bindingResult, messageSource)); return "owner/EditForm"; } clinic.storeOwner(owner); return "redirect:/owner/" + owner.getId(); }
@Override public String getTelephone() { return delegate.getTelephone(); }
@Override public List<Pet> getPets() { return delegate.getPets(); }
@Override public String getCity() { return delegate.getCity(); }
@Override public String getAddress() { return delegate.getAddress(); }
@Override public String getLastName() { return delegate.getLastName(); }
@Override public boolean isNew() { return delegate.isNew(); }
@Override public Integer getId() { return delegate.getId(); }