Announcement Announcement Module
Collapse
No announcement yet.
Flash scope not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Flash scope not work

    Hello,

    I can't understand problem with flash scope.
    I tried to redirect using flash attributes, but it's not work if I redirect to different controller

    Code:
    @RequestMapping(value = "/avatar", method = RequestMethod.GET)
        public String avatar(Model model) {
            UserShortForm form = userService.getUserShortInfo(SecurityUtil.getUserId());
            model.addAttribute("userForm", form);
            return "user/avatar";
        }
    
        @RequestMapping(value = "/avatar", method = RequestMethod.POST)
        public String uploadAvatar(@RequestParam(value = "avatar.content_type", required = false) String type,
                                   @RequestParam(value = "avatar.path", required = false) String path,
                                   Model model,
                                   RedirectAttributes attributes) {
            if (type == null  || path == null) {
                attributes.addAttribute("error", "error");
                model.addAttribute("error", "error");
                return "redirect:/user/avatar";
            }
            return "user/avatar";
        }
    Parameter sends as URL param: /user/avatar?error=error
    Another method with model attribute works fine

  • #2
    You aren't setting flash attributes.. Use addFlashAttribute instead...

    addAttribute - used to add redirect parameters
    addFlashAttribute - used to add flash attributes

    Comment


    • #3
      Opps, I'm not careful. Thanks

      Comment

      Working...
      X