I am adding to the ModelMap
a Map
which contains a list to go on a drop down an I am populating the ModelAttribute when the form initialises:
@RequestMapping(method = RequestMethod.GET)
public String initForm(HttpServletRequest httpRequest, ModelMap model)
{
model.addAttribute("myList", myMap);
return "MyForm";
}
It works as expected however when the user submits the form this list is lost from the map.
@RequestMapping(method = RequestMethod.POST, value ="/dosearch")
public String processSearch(... ModelMap model)
{
.....
return new ModelAndView("MyForm",model);
This approach above doesn't work.
How can I prserve the map between form submits?
No. Even a flash scope won't help you here, because you are not using redirect-after-post. Here are the options:
/dosearch
and you'll be able to get them from the request