Announcement Announcement Module
Collapse
No announcement yet.
how to get current session in POJO? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to get current session in POJO?

    Hi all,

    I just started using spring and feel things are so implicit. I am wondering how to get the current session. For example,

    <bean id="a" class="my.domain.ClassA">
    <bean id="b" class="my.domain.ClassB">
    </bean>
    </bean>

    How can I get the current session within either a or b?

    thanks,

  • #2
    Do class A or class B extend any of the Spring MVC classes? If so, which ones? If not, what exactly are you trying to accomplish? You may need to rethink your class structure.

    Comment


    • #3
      You asked a very good question.

      I am tasked to re-organizing the code into the spring framework. The code was written to POJO + dwr. I know DWR can allow you to access the session in any object created by dwr.

      Code:
         HttpSession session = uk.ltd.getahead.dwr.WebContextFactory.get().getSession(false);
         session.setAttribute("B", this);
         session.setAttribute("A", a);
      Neither A or B implements any servlet or extra dwr classes.

      I think I may understand Spring in a different/wrong way.

      Comment


      • #4
        You shouldn't try to read HttpSessions from within your domain pojo's. In fact, they should remain unaware of their context in general.

        Take a look at the petclinic sample application that comes with the spring distribution. It can give you a fairly good idea about how to organize your code.

        Originally posted by liangchen76 View Post
        You asked a very good question.

        I am tasked to re-organizing the code into the spring framework. The code was written to POJO + dwr. I know DWR can allow you to access the session in any object created by dwr.

        Code:
           HttpSession session = uk.ltd.getahead.dwr.WebContextFactory.get().getSession(false);
           session.setAttribute("B", this);
           session.setAttribute("A", a);
        Neither A or B implements any servlet or extra dwr classes.

        I think I may understand Spring in a different/wrong way.

        Comment


        • #5
          Thanks for suggestion. I will think about them.

          If anyone cares to know, I found out your can still get the current session with WebContextFactory as usual. The only difference is that those beans needs to be marked for a spring creator in dwr.xml .

          Comment

          Working...
          X