예제 #1
0
  /**
   * 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;
  }
예제 #2
0
  /** 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();
  }
예제 #3
0
 @Override
 public String getTelephone() {
   return delegate.getTelephone();
 }
예제 #4
0
 @Override
 public List<Pet> getPets() {
   return delegate.getPets();
 }
예제 #5
0
 @Override
 public String getCity() {
   return delegate.getCity();
 }
예제 #6
0
 @Override
 public String getAddress() {
   return delegate.getAddress();
 }
예제 #7
0
 @Override
 public String getLastName() {
   return delegate.getLastName();
 }
예제 #8
0
 @Override
 public boolean isNew() {
   return delegate.isNew();
 }
예제 #9
0
 @Override
 public Integer getId() {
   return delegate.getId();
 }