/**
  * Handles client deletion or cancellation, redirecting to the listing page in either case.
  *
  * @param command the command field from the form
  * @param clientId the ID of the client to be deleted
  * @return redirect to the listing page
  */
 @RequestMapping(value = "delete", method = RequestMethod.POST)
 public String delete(@RequestParam String command, @RequestParam Integer clientId) {
   if (COMMAND_DELETE.equals(command)) {
     clientService.deleteClient(clientId);
   }
   return "redirect:/client/list";
 }
 /**
  * Renders an edit form for an existing client record.
  *
  * @param clientId the ID of the client to edit
  * @return edit view populated from the client record
  */
 @RequestMapping(value = "edit/{clientId}", method = RequestMethod.GET)
 public ModelAndView edit(@PathVariable Integer clientId) {
   ModelAndView mav = new ModelAndView("client/edit");
   mav.addObject("client", clientService.readClient(clientId));
   mav.addObject("fullContactList", fullContactList());
   mav.addObject("errors", new ArrayList<String>());
   return mav;
 }
 /**
  * Renders a view form for an existing client record.
  *
  * @param clientId the ID of the client to view
  * @return view populated from the client record
  */
 @RequestMapping(value = "view/{clientId}", method = RequestMethod.GET)
 public ModelAndView view(@PathVariable Integer clientId) {
   ModelAndView mav = new ModelAndView("client/view");
   Client client = clientService.readClient(clientId);
   mav.addObject("client", client);
   mav.addObject("contactList", contactList(client));
   mav.addObject("errors", new ArrayList<String>());
   return mav;
 }
 /**
  * Validates and saves a new client. On success, the user is redirected to the listing page. On
  * failure, the form is redisplayed with the validation errors.
  *
  * @param client populated form bean for the client
  * @return redirect, or create view with errors
  */
 @RequestMapping(value = "create", method = RequestMethod.POST)
 public ModelAndView create(@RequestParam String command, Client client) {
   List<String> errors = clientService.validateClient(client);
   if (COMMAND_ADD_CONTACT.equals(command)) {
     Client updatedClient = clientService.updateAndReturnClient(client);
     ModelAndView mav = new ModelAndView("client/edit");
     mav.addObject("client", updatedClient);
     mav.addObject("contacts", contactList(updatedClient));
     mav.addObject("errors", errors);
     return mav;
   } else if (errors.isEmpty()) {
     clientService.createClient(client);
     return new ModelAndView("redirect:/client/list");
   } else {
     ModelAndView mav = new ModelAndView("client/create");
     mav.addObject("client", client);
     mav.addObject("errors", errors);
     return mav;
   }
 }
 /**
  * Renders the listing page.
  *
  * @return list view populated with the current list of people
  */
 @RequestMapping(value = "list", method = RequestMethod.GET)
 public ModelAndView list() {
   ModelAndView mav = new ModelAndView("client/list");
   mav.addObject("clients", clientService.listClients());
   return mav;
 }
 /**
  * Renders the deletion confirmation page.
  *
  * @param clientId the ID of the client to be deleted
  * @return delete view populated from the client record
  */
 @RequestMapping(value = "delete/{clientId}", method = RequestMethod.GET)
 public ModelAndView delete(@PathVariable Integer clientId) {
   ModelAndView mav = new ModelAndView("client/delete");
   mav.addObject("client", clientService.readClient(clientId));
   return mav;
 }