You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Sean Schofield <se...@gmail.com> on 2005/02/12 22:17:53 UTC

Can JSF Renderers have class variables?

I was wondering if a renderer needs to be thread safe?  Specifically I
was hoping to use a class variable as a "counter" so I could keep
track of various counts while I called a certain method recursively.

Re: Can JSF Renderers have class variables?

Posted by Sean Schofield <se...@gmail.com>.
> I guess you could also use a ThreadLocal, also, but that's probably
> more of a hack than anything else.

I think ThreadLocal is probably more appropriate in the case where you
have multiple objects that need to access the same instance of the
object per thread.  Since I am only talking about one object (the
renderer), Craig's solutions seems preferable.

> -Heath Borders-Wing

sean

Re: Can JSF Renderers have class variables?

Posted by Heath Borders <he...@gmail.com>.
Generally, that's what we've been doing in our renderers.

I guess you could also use a ThreadLocal, also, but that's probably
more of a hack than anything else.


On Sat, 12 Feb 2005 14:39:01 -0800, Craig McClanahan <cr...@gmail.com> wrote:
> On Sat, 12 Feb 2005 16:17:53 -0500, Sean Schofield
> <se...@gmail.com> wrote:
> > I was wondering if a renderer needs to be thread safe?  Specifically I
> > was hoping to use a class variable as a "counter" so I could keep
> > track of various counts while I called a certain method recursively.
> >
> 
> Yes, they have to be thread safe ... there's only one instance in
> memory (just like a servlet).
> 
> The best way for a renderer to keep track of stuff like counters would
> be to use one of the generic attributes on the component it is
> rendering.  If you use fully qualified attribute names
> (com.mycompany.foo.COUNTER) you'll avoid collisions with other code
> that is doing the same sort of thing.
> 
> Craig
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: Can JSF Renderers have class variables?

Posted by Craig McClanahan <cr...@gmail.com>.
On Sat, 12 Feb 2005 16:17:53 -0500, Sean Schofield
<se...@gmail.com> wrote:
> I was wondering if a renderer needs to be thread safe?  Specifically I
> was hoping to use a class variable as a "counter" so I could keep
> track of various counts while I called a certain method recursively.
> 

Yes, they have to be thread safe ... there's only one instance in
memory (just like a servlet).

The best way for a renderer to keep track of stuff like counters would
be to use one of the generic attributes on the component it is
rendering.  If you use fully qualified attribute names
(com.mycompany.foo.COUNTER) you'll avoid collisions with other code
that is doing the same sort of thing.

Craig