Example #1
0
  /**
   * Delete.
   *
   * @param id the id
   * @param model the model
   * @param redirectAttrs the redirect attrs
   * @param locale the locale
   * @return the string
   */
  @RequestMapping("/delete/{id}")
  public String delete(
      @PathVariable Long id, Model model, RedirectAttributes redirectAttrs, Locale locale) {
    Item item = itemService.get(id);
    if (item != null) {
      itemService.delete(id);

      redirectAttrs.addFlashAttribute(
          "message",
          MessageFormat.format(
              messageSource.getMessage("item.deleted", null, locale), item.getName()));

      return "redirect:/item/list";
    }
    model.addAttribute(
        "message",
        MessageFormat.format(messageSource.getMessage("item.deleted.failed", null, locale), id));
    return "/item/form";
  }
Example #2
0
 /**
  * Save.
  *
  * @param item the item
  * @param bindingResult the binding result
  * @param model the model
  * @param redirectAttrs the redirect attrs
  * @param locale the locale
  * @return the string
  */
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 public String save(
     @Valid Item item,
     BindingResult bindingResult,
     Model model,
     RedirectAttributes redirectAttrs,
     Locale locale) {
   if (!bindingResult.hasErrors()) {
     Item savedItem = itemService.save(item);
     redirectAttrs.addFlashAttribute(
         "message", messageSource.getMessage("item.saved", null, locale));
     return "redirect:/item/view/" + savedItem.getId() + "?success";
   }
   model.addAttribute("readonly", false);
   return "/item/form";
 }
Example #3
0
 /**
  * Update.
  *
  * @param id the id
  * @param model the model
  * @return the string
  */
 @RequestMapping("/edit/{id}")
 public String update(@PathVariable Long id, Model model) {
   model.addAttribute("item", itemService.get(id));
   model.addAttribute("readonly", false);
   return "/item/form";
 }
Example #4
0
 /**
  * View.
  *
  * @param id the id
  * @param model the model
  * @return the string
  */
 @RequestMapping("/view/{id}")
 public String view(@PathVariable Long id, Model model) {
   model.addAttribute("item", itemService.get(id));
   model.addAttribute("readonly", true);
   return "/item/form";
 }
Example #5
0
 /**
  * List.
  *
  * @param model the model
  * @return the string
  */
 @RequestMapping("/list")
 public String list(Model model) {
   model.addAttribute("items", itemService.list());
   return "/item/list";
 }