@RequestMapping(value = "/admin/taxRates/insert", method = RequestMethod.POST) public String taxRateInsertPerform( @RequestParam(value = "page", defaultValue = FIRST_PAGE) int page, @Valid TaxRate thisTaxRate, BindingResult result, Model model) { logger.info("TaxRate: " + thisTaxRate.toString()); if (result.hasErrors()) { int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); model.addAttribute("menuCategory", menuCategory); Pageable pageRequest = new PageRequest(page, PAGE_SIZE, Sort.Direction.ASC, "priority"); Page<TaxRate> taxRates = taxRateService.findAll(pageRequest); model.addAttribute("taxRates", taxRates); model.addAttribute("thisTaxRate", thisTaxRate); return "admin/taxes/taxRatesInsertForm"; } else { taxRateService.create(thisTaxRate); return "redirect:/admin/taxRates/" + thisTaxRate.getId() + "?page=" + page; } }
@RequestMapping(value = "/admin/taxRates/{taxRateId}/edit", method = RequestMethod.POST) public String taxRateEditSave( @PathVariable long taxRateId, @RequestParam(value = "page", defaultValue = FIRST_PAGE) int page, @Valid TaxRate thisTaxRate, BindingResult result, Model model) { logger.info("TaxRate: " + thisTaxRate.toString()); if (result.hasErrors()) { int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); model.addAttribute("menuCategory", menuCategory); model.addAttribute("thisTaxRate", thisTaxRate); Pageable pageRequest = new PageRequest(page, PAGE_SIZE, Sort.Direction.ASC, "priority"); Page<TaxRate> taxRates = taxRateService.findAll(pageRequest); model.addAttribute("taxRates", taxRates); return "admin/taxes/taxRatesEditForm"; } else { TaxRate loadedTaxRate = taxRateService.findById(taxRateId); loadedTaxRate.setLastModified(new Date()); loadedTaxRate.setPriority(thisTaxRate.getPriority()); loadedTaxRate.setTaxRate(thisTaxRate.getTaxRate()); loadedTaxRate.setTaxClass(thisTaxRate.getTaxClass()); loadedTaxRate.setTaxZone(thisTaxRate.getTaxZone()); taxRateService.update(loadedTaxRate); return "redirect:/admin/taxRates/" + taxRateId + "?page=" + page; } }