0
I’m using @Restcontroller to manage different Forms/actions on the same page (with Thymeleaf), and it’s working properly, but when calling method (triggered via button on page) when returning to the page the URL in the browser is not 'reset' even if I recreate my Modelview Every time:
Example:
Initial URL: http://localhost:8090/project/v1/controller/
URL after some action on Restcontorller: http://localhost:8090/project/v1/controller/actionA
Desired URL when returning to page after button-fired method: http://localhost:8090/project/v1/controller/
Code: //method I use to open the page @Requestmapping(value = "/", method = Requestmethod.GET) public Modelandview index(){ Modelandview Mav = new Modelandview(); Mav.addObject("myObj", this.someMethods()); Mav.setViewName("index"); //my page Return Mav; }
//método disparado pelo botão na página, contendo a ação
@RequestMapping(value = "/actionA", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, params = "action=actionA")
public ModelAndView actionA(...) {
ModelAndView mav = new ModelAndView();
mav.addObject("myObj", this.someMethods());
mav.setViewName("index"); //a mesma página
return mav;
}
I cannot use the same value parameter because I use it in my Forms/actions to define which method to fire in my restcontroller, example:
<form id="action" method="POST" th:object="${Object}"
th:action="@{/v1/emulador-central/action}">
...
<button type="submit" name="action" value="actionA" class="btn btn-primary">Aprovar</button>
<button type="submit" name="action" value="actionB" class="btn btn-primary" style="float:right;">Reprovar</button>
...
</form>
I tried to use redirect and it didn’t work, I also tried to create a POST method to create Modelandview and then return it to my index page, another flaw. Can anyone guide me how to make it work properly? Thank you.
If someone is facing the same problem: so far I have not found the expected solution, when I find update.
– WyllianNeo