Announcement Announcement Module
Collapse
No announcement yet.
RedirectAttributes addAllAttributes and addFlashAttribute don't mix Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RedirectAttributes addAllAttributes and addFlashAttribute don't mix

    Hi,

    I'm trying to use RedirectAttributes and I have already a working example.
    I was trying to use them somewhere else and came across this scenario

    Code:
    @Controller
    public class MyController {
        
        @RequestMapping(value="/pageB", method = RequestMethod.GET)
        public String getPageB(Model model, HttpSession session,  
                @ModelAttribute("instantCommonForm") InstantCommonForm form)
        {
            return "viewB";
        }
        
        @RequestMapping(value="/pageA", method = RequestMethod.GET)
        public String getPageA(Model model, HttpSession session, HttpServletRequest request,
                @RequestParam(value="myVar", defaultValue="0") boolean myVar,
                RedirectAttributes redirect)
        {
            
            redirect.addAllAttributes(request.getParameterMap()); // IMPORTANT LINE!
            
            redirect.addFlashAttribute("myVar", myVar);
            return "redirect:/pageB";
        }
    }
    If the important line is present "myVar" won't be available on the pageB Model object. I've been looking through the source code but I still don't understand why those two don't mix..

    Any ideas?
Working...
X