Global variable in Component Class issue

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Global variable in Component Class issue

ramandeep0015
Hi Hippo Team

I have declared some global variables in Component Class and initializing them in deBeforeRender  and again using them in doAction

But i am facing issue

if user 1 load the page then  global variable xyz gets initialized in doBeforeRender to value user1
and in same time user 2 loads the page then xyz value changes to user2
then user 2 submits till now its ok
 BUT when user 1 submits he gets values as user2

xyz variable is not static

Please help

Thanks
Ramandeep Singh
Reply | Threaded
Open this post in threaded view
|

Re: Global variable in Component Class issue

Mathijs den Burger
Hi Ramandeep,

HST components are not thread-safe [1], that's why you see this behavior.
What are you trying to achieve?

best,
Mathijs

[1] http://www.onehippo.org/7_7/library/concepts/component-development/hstcomponent-java-class.html


On Thu, Oct 18, 2012 at 10:39 AM, ramandeep0015 <[hidden email]> wrote:

> Hi Hippo Team
>
> I have declared some global variables in Component Class and initializing
> them in deBeforeRender  and again using them in doAction
>
> But i am facing issue
>
> if user 1 load the page then  global variable xyz gets initialized in
> doBeforeRender to value user1
> and in same time user 2 loads the page then xyz value changes to user2
> then user 2 submits till now its ok
>  BUT when user 1 submits he gets values as user2
>
> xyz variable is not static
>
> Please help
>
> Thanks
> Ramandeep Singh
>
>
>
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Global-variable-in-Component-Class-issue-tp7579568.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Global variable in Component Class issue

Wouter Danes-2
In reply to this post by ramandeep0015
Hi Ramandeep,

HST Components act like servlets: they are "singletons" inside the container / webapp.
You should never use class variables. If you really need "variables", use a ThreadLocal<>.
You can pass things as parameters to your methods, or using the request attributes, requests are namespaced to the current component.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of ramandeep0015
Sent: donderdag 18 oktober 2012 10:40
To: [hidden email]
Subject: [Hippo-cms7-user] Global variable in Component Class issue

Hi Hippo Team

I have declared some global variables in Component Class and initializing them in deBeforeRender  and again using them in doAction

But i am facing issue

if user 1 load the page then  global variable xyz gets initialized in doBeforeRender to value user1 and in same time user 2 loads the page then xyz value changes to user2 then user 2 submits till now its ok  BUT when user 1 submits he gets values as user2


xyz variable is not static

Please help

Thanks
Ramandeep Singh




--
View this message in context: http://hippo.2275632.n2.nabble.com/Global-variable-in-Component-Class-issue-tp7579568.html
Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Global variable in Component Class issue

ramandeep0015
OK .. Got it.

Thank you :)
Reply | Threaded
Open this post in threaded view
|

Re: Global variable in Component Class issue

ramandeep0015
In reply to this post by Mathijs den Burger
ok. i got it now

Thanks You