Reputation: 441
Using spring boot, I have a timetable page.
You can click a square, which opens up a small form with which you can add or remove the class objects from the timetable (which are saved in a database).
My issue is, when you click 'add' (or remove), while it successfully adds/removes that object from the timetable, you have to refresh the page in order to see the class be added/removed on the timetable. It appears like nothing happens when add is clicked from the user's perspective (until they manually refresh the page).
The post method redirects back to the timetable page get. I tried having it redirect to another mini get method, which then redirected back to the original timetable page; but from the browser side it still didn't look like anything was happening - just remaining on the same page with the original problem. Would love to hear a potential solution, thanks!
Edit: Here's an example of my get and post methods:
@GetMapping("/timetable/{id}/{semId}")//This method displays timetable.
public String timetable(@PathVariable(value = "id") String id, Model model,
@PathVariable(value = "semId") String semId) {
//code..
model.addAttribute("x", x);
return "timetable";
}
@PostMapping("/timetable/{id}/{semId}")
public String timetablePost(@ModelAttribute TimetableClassDto dto, @PathVariable(value = "id") String id,
Model model, @PathVariable(value = "semId") String semId) {
//code..
return "redirect://timetable/00/" + semId;
}
Upvotes: 0
Views: 5375
Reputation: 130
Are you supposed to have two // in your redirect? I have something similar in my code and it works fine. However, I create a url first then return that. Also, make sure your get mapping is properly filling out the object based on the new parameters gotten from the redirect. Use the following:
??
String url = "redirect://timetable/00/" + semId;
return url;
Upvotes: 1