title: How to keep an model attribute after a redirection?
body: <p>I have an object that I fill in a form in the view "submit".</p>
  
  <p>After that, it post the object "WelcomeMessageFinder" in the view "return".</p>
  
  <p>I call a service with that use this object. If the service fails, I want to redirect to the view "submit" and keep the form filled with the previous values.</p>
  
  <p>My issue is that I don't find how to keep the "WelcomeMessageFinder" object after the redirect. It always create a new empty object.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>@Controller
  @SessionAttributes("welcomeMessageFinder")
  public class SandBoxController extends PortalWebuiController {
      @ModelAttribute("welcomeMessageFinder")
      public WelcomeMessageFinder welcomeMessageFinder() {
          return new WelcomeMessageFinder();
      }
  
      @RequestMapping(value = "/submit", method = RequestMethod.GET)
      public String submit(WelcomeMessageFinder welcomeMessageFinder, Model model, SessionStatus sessionStatus, HttpSession httpSession) {
          // On Init : a new WelcomeMessageFinder is created
          // After redirect : I want to keep the filled WelcomeMessageFinder but a new one is created ...
          model.addAttribute("zenithUserSession", zenithUserSession);
          return "submitwelcomemessage";
      }
  
      @RequestMapping(value = "/return", method = RequestMethod.POST)
      public String retun(
              WelcomeMessageFinder welcomeMessageFinder,
              Model model,
              RedirectAttributes redirectAttributes,
              SessionStatus sessionStatus, HttpSession httpSession) {
          // welcomeMessageFinder contains the parameters I enter in the form.
          redirectAttributes.addFlashAttribute("welcomeMessageFinder", welcomeMessageFinder);
          return "redirect:/submit";
      }
  }
  </code></pre>
  
  <p>What can I do to keep the same WelcomeMessageFinder object before and after the redirect ?</p>
  
  <p>I find this <a href="https://stackoverflow.com/questions/17086216/why-do-sessionattributes-get-cleared-on-get-redirect" title="question">question</a> that says that I can't use SessionAttributes with redirect because it doesn't keep the session. And it says to use RedirectAttributes but the attributes seems to be reinitialized.</p>
  
  <p>EDIT :</p>
  
  <p>I finally found my error. This code works, the problem is with my class WelcomeMessageFinder. To add an object in the flash session, this object need to be Serializable. I forget to implements Serializable in my class.</p>
  
  <p>After adding this, it works fine.</p>