@RequestMapping(value = "/web/transfer", method = RequestMethod.GET) public String showTransferForm( WebRequest request, Model model, String target, @ModelAttribute("loggedAccount") Account originator) { Account beneficiary = new Account(); beneficiary = accountService.getAccountByLogin(target); TransferDTO transfer = new TransferDTO(); transfer.setOriginator(originator); transfer.setBeneficiary(beneficiary); transfer.setAmmount(new BigDecimal(0)); model.addAttribute("transfer", transfer); return "transfer"; }
@RequestMapping(value = "/web/transferBegin", method = RequestMethod.GET) public ModelAndView transferBegin( WebRequest request, @ModelAttribute("transfer") TransferDTO currentTransfer, String coinAmmount, BindingResult result, Errors errors) { ModelAndView model = new ModelAndView(); TransferDTO registered = new TransferDTO(); currentTransfer.setAmmount(new BigDecimal(coinAmmount)); if (currentTransfer.getAmmount().intValue() == 0) { result.rejectValue("ammount", "ammount.zero"); model.addObject("error", "Cannot transfer zero coins"); } if (currentTransfer.getOriginator().getCredit().compareTo(currentTransfer.getAmmount()) < 0) { result.rejectValue("ammount", "ammount.notenough"); model.addObject("error", "Not enough coins for this transfer"); } if (!result.hasErrors()) { registered = accountService.transferCoins(currentTransfer); } if (registered == null) { result.rejectValue("ammount", "ammount.error"); model.addObject("error", "error executing transfer, please try again later"); } if (result.hasErrors()) { model.addObject("transfer", currentTransfer); model.setViewName("transfer"); } else { model.clear(); model.addObject("loggedAccount", currentTransfer.getOriginator()); model.addObject("msg", "Transfer Completed"); model.setViewName("welcome"); } return model; }