@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET) public String editAction( final RedirectAttributes redirectAttributes, @PathVariable Long id, Model model) { Expense expense = expenseService.findOne(id); if (expense.isSubmitted()) { redirectAttributes.addFlashAttribute("message", "message.record.not.editable"); return "redirect:/userexpense/show/" + expense.getId(); } model.addAttribute("expensetypes", expensetypeService.findAll()); model.addAttribute("userexpenseAttribute", expense); return "/userexpense/form"; }
@RequestMapping(value = "/save", method = RequestMethod.POST) public String saveAction( final RedirectAttributes redirectAttributes, Principal principal, @ModelAttribute("userexpenseAttribute") @Valid Expense formData, BindingResult result, Model model) { if (result.hasErrors()) { model.addAttribute("expensetypes", expensetypeService.findAll()); return "/userexpense/form"; } Member member = memberService.findOneByUsername(principal.getName()); formData.setMember(member); Expense expense = expenseService.save(formData); redirectAttributes.addFlashAttribute("message", "message.completed.save"); return "redirect:/userexpense/show/" + expense.getId(); }
@RequestMapping(value = "/new", method = RequestMethod.GET) public String newAction(Model model) { model.addAttribute("expensetypes", expensetypeService.findAll()); model.addAttribute("userexpenseAttribute", new Expense()); return "/userexpense/form"; }