I have a spring-boot application, with thememleaf. I am reloading the page and redirecting it to the same page, so I expect the page elements to be refreshed:
@GetMapping("/suggested-events/vote/{eventId}") public String voteForEvents(Model model, @PathVariable("eventId") Long eventId, @RequestParam(value = "message", required = false) String message ) { log.info("The message is: "+message); SuggestedEvent event = suggestedEventService.findSuggestedEventById(eventId); ArrayList<SuggestedEvent> events = suggestedEventService.findSuggestedEventsByArea(event.getArea()); model.addAttribute("mainEvent",event); model.addAttribute("events",events); model.addAttribute("message",message); return "/suggested-event/vote"; }
and when the button is clicked in the view, it invokes the following post method:
@PostMapping("/suggested-events/vote") public String voteForASuggestedEvent(RedirectAttributes redirectAttributes){ log.info("You have made a vote"); redirectAttributes.addAttribute("message", "Success"); return "redirect:/suggested-events/vote/1"; }
This second controller method performs an operation a, makes a message and redirects it to the first method. Thus, it is successfully redirected to the first method and writes
log.info("The message is: "+message);
but it doesnβt refresh my page, and I donβt get the message as a model ?
When I redirect to the first method, I expect it to add message to my models:
model.addAttribute("message",message);
But it is not added to my page
redirect spring spring-mvc thymeleaf
user5363938
source share