0

my openxava application require some session scoped data in so many places i.e. current time/time zone of the user. Openxava uses ThreadLocal variables to keep Current login user information of a particular session(Check OX source org.openxava.util.Users). It works out of the box. I also followed same but i got in deterministic results. Some time it works some time it give wrong results. I do not understand it's behavior. Where am i making mistake. From my understanding of ThreadLocal variable, neither case it should not work. How OX guarantees one to one mapping between Thread and Session. Pls help me

steave55
  • 9
  • 1

1 Answers1

0

How OX guarantees one to one mapping between Thread and Session

Such mapping does not exist. The session objects are alive for the whole user session while the ThreadLocal variable are attached to the thread. It's not a good idea to use session state from model layer (entities), because the model can be used from other views, applications, web applications, from batch processes, etc. so you cannot rely on session state.

So, you first option should be to get the session data from controller layer (actions) and to assign it to enties. However, if you really want to move session data from controller to model (or any other part of your application) you can use ThreadLocal, but the value you set in this variable is only valid in that specific request, so you must move from session to ThreadLocal var in each request.

javierpaniza
  • 677
  • 4
  • 10
  • >It's not a good idea to use session state from model layer (entities). I do not need it in the model it is in the actions. how i can store session scoped data in java? – steave55 Dec 29 '12 at 01:50
  • Hi steave55, and that case usa @Inject (JSR-330) from you action. Look at: http://openxava.wikispaces.com/controllers_en#Chapter%207:%20Controllers-Dependency%20injection-@Inject%20%28JSR-330%29%20%28new%20in%20v4m2%29 – javierpaniza Jan 02 '13 at 12:54