Results 1 to 4 of 4

Thread: Spring newbie - http session question

  1. #1
    Join Date
    Sep 2004
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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.

  3. #3
    Join Date
    Sep 2004
    Posts
    3

    Default

    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...

  4. #4
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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 at 09:53 AM.

Similar Threads

  1. Replies: 8
    Last Post: Jan 5th, 2006, 12:07 AM
  2. Replies: 0
    Last Post: Aug 25th, 2005, 05:11 AM
  3. Newbie Question - The Ideal Spring Solution
    By conorp in forum Architecture
    Replies: 3
    Last Post: Aug 23rd, 2005, 03:22 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •