Yes, it's possible.
Personally, I put this logic in setupForRequest method of my engine.
I created a class, UserContext, like this:
public class UserContext {
static ThreadLocal _visitLocal = new ThreadLocal();
public static Object getVisit() {
return (Visit) _visitLocal.get();
}
public static void setVisit(Object visit) {
_visitLocal.set(visit);
}
}
And then, in setupForRequest:
protected void setupForRequest(RequestContext context) {
if(getVisit() !=null)
UserContext.setVisit(getVisit());
}
NOTE: getVisit() in baseEngine, do not create the visit object, like
the Page does.
So, anywhere you can put:
UserContext.getVisit().
The same you can do with Global object.
Let me know if that helped you.
On 5/31/05, Hensley, Richard <[EMAIL PROTECTED]> wrote:
> Sarah,
>
> Do you have a Visit?
>
> This sounds like session specific information that is normally stored in the
> Visit. I would consider constructing a method in my Visit that knows how to
> navigate the global object correctly.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>
> Sent: Tuesday, May 31, 2005 9:49 AM
> To: [email protected]
> Subject: ThreadLocal example pleeeeease!
>
> Could anyone of you post a quick example how to correctly
> use ThreadLocal within a Tapestry page and a Tapestry component?
>
> My global object currently is a map of group data and the key is the group
> key. Different page getter methods need parameters that is derived from the
> group data .....
>
> E.g. administrator is on:
>
> admin.domain.com
>
> moderators on moderators.domain.com
>
> users on www.domain.com
>
> guests on guests.domain.com
>
> a method that is called getMenuOptions should retrieve the menu options.
>
> The menu can contain 4 different kinds of data. So it is all in a global map
> and the database is only queried once.
>
> But this leads to having to parse the map all the time
> the method getMenuOptions or any other method that will indirectly call it,
> is called.
>
> and I want to sort of shift it into some sort of local variables to be able
> to directly access it.
>
> Is that possible using ThreadLocal ? If so, how ?
>
> Thank you!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]