struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken <>
Subject Re: Session object null
Date Tue, 18 May 2010 18:17:19 GMT
Thank you Dale,

Let me see if I understand this correctly.  Since the action object has
not been created yet, and this is in a different thread... I can not get
the correct context...  Although the session objects _is_ someplace...
It will also not work in the constructor even if the class is
SessionAware because the object must exist before setSession(Map m)
could be called... 

I should really be treating execute() as my constructor for now... until
I better understand when the session variable becomes available.
Struts2 needs to see who I am before it knows my session right?  So it
isn't going to provide it to me until it has done a certain amount of
set up?


On Tue, 2010-05-18 at 12:49 -0400, Dale Newfield wrote: ActionContext my
current method is local to the thread so I can't use that 

> On 5/18/10 12:35 PM, Ken wrote:
> > What I don't understand is I have an object who's constructor needs
> > session data...
> > So it calls:
> > Map session = ActionContext.getContext().getSession();
> >
> > But session is always null...
> Explains that this static method works by looking up the value in a 
> ThreadLocal: "Returns the ActionContext specific to the current thread."
> So if that constructor is happening within the same thread in which the 
> request was originally being processed, and after xwork finishes setting 
> up that context, it should work:
> "The ActionContext is thread local which means that values stored in the 
> ActionContext are unique per thread. See the ThreadLocal class for more 
> information."
> But random code in a random thread occurring at a random time cannot 
> rely on ActionContext.getContext().
> I'd check out the *Aware interfaces if I were you.
> -Dale
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message