// add a new paymentCard - form @RequestMapping(value = "add", method = RequestMethod.GET) public String addForm(Model model) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); model.addAttribute(new PaymentCard()); return "cards/add"; }
// update a paymentCard @RequestMapping(method = RequestMethod.POST) public String update(@Valid PaymentCard paymentCard, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/edit"; } paymentCardService.updatePaymentCard(paymentCard); String message = "Succesfully updated Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); }
// edit a specific PaymentCard - form @RequestMapping(value = "{id}/edit", method = RequestMethod.GET) public String editForm(@PathVariable Long id, Model model) { PaymentCard paymentCard; List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); try { paymentCard = paymentCardService.findPaymentCardById(id); } catch (NoResultException e) { return "cards/invalidPaymentCard"; } model.addAttribute(paymentCard); return "cards/edit"; }
// add a paymentCard @RequestMapping(method = RequestMethod.PUT) public String add( @Valid PaymentCard paymentCard, BindingResult bindingResult, Principal currentUser, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/add"; } if (currentUser != null) { paymentCardService.addPaymentCard(paymentCard, currentUser.getName()); String message = "Succesfully added Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); } else { // TODO: return error return "redirect:/cards/add"; } }