Announcement Announcement Module
Collapse
No announcement yet.
Spring newbie - http session question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring newbie - http session question

    I have looked over the tutorials and don't quite understand how to manage HttpSession objects using Spring.

    If I want to save an object in the session conditional of a successful onSubmit(), where and how should I do it?

  • #2
    Management of the HttpSession has to be done by yourself. Some controllers (especially the AbstractFormController and its subclasses) put something in the session for the duration of the form requests (showing the form, submitting it, reshowing it because of validation errors, etcetera).

    If you want to put something int he session, you'd have to override the onSubmit method taking an HttpServletRequest and get the Session yourself using request.getSession(). There are no real convenience features that allow for session management except for the 'requireSession' property on the AbstractController (all extending controllers also have it). If you're setting this and there is no session associated with the user, an exception will be thrown.

    Comment


    • #3
      In that case, where multi-user (a.k.a. web) applications are concerned, this represents a major shortcoming in Spring's IoC architecture.

      Every web developer must at times initialize objects based on session specific data. If the IoC mechanism does not provide a means to access session data, instantiation/configuration of session dependent objects must take place outside the scope of the bean container (i.e. inside controllers, session listeners or request filters). Since these beans are dispersed throughout the application, they can become a mess to manage (i.e. have to keep track of parameter ids, etc...)

      JSF provides an elegant backing bean model that incorporates http request/session/application scoping. Is there no way to replicate this with Spring? (without resorting to JSF-Spring bridge)


      Your insights would be appreciated...

      Comment


      • #4
        First of all, Spring isn't focusing on web applications only. Spring's IoC infrastructure just provides a clean way to wire you objects, regardless of whether the application is multi-user or not.

        That doesn't mean there are elegant solutions available. Another user just happened to have the same problem and he came up with a solution using target sources and a bit of AOP.

        Have a read: [url]http://forum.springframework.org/showthread.php?t=10357[url]

        I'll be spending more time on this, I think it's an interesting way to solve this.
        Last edited by robyn; May 14th, 2006, 09:53 AM.

        Comment

        Working...
        X