How do I keep a ModelMap form between forms?

I add to ModelMap

a Map

which contains the list to navigate down. I fill in the ModelAttribute when the form is initialized:

@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 transfer the map between form submissions?

+3


source to share


1 answer


Not. Even the flash area won't help you here because you are not using redirect-after-post. Here are the options:



  • all values ​​are output in html form, then they will be sent to /dosearch

    and you can get them from request
  • use session to store values ​​(worst case)
+1


source







All Articles