コード例 #1
0
 // 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";
 }
コード例 #2
0
 // 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();
 }
コード例 #3
0
 // 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";
 }
コード例 #4
0
 // 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";
   }
 }