File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Are managed-beans shared? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Are managed-beans shared?" Watch "Are managed-beans shared?" New topic

Are managed-beans shared?

Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
Hi, fellas

I was thinking about some things, and I am not sure about how JSF manages my beans. I know that a managed-bean stored in session scope is shared throughout all requests in that user's session, but what about request scope managed-beans? Are they pooled or even shared accross multiple requests? I need to know if it is safe to use instance variables in my backing beans. I know it does not work for Servlets and Struts but, hey, this is JSF! Clarifying is very appreciated

Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
The simplest thing to do would be to place a System.out.println in your bean's constructor and find out... And what you would find is that request scope beans are not reused -- they are constructed when needed. These beans are usually there to back a HTML FORM, so they are cheap to construct -- there should be no need to "optimize" this by pooling or reuse -- that would only slow things down!

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: Are managed-beans shared?
It's not a secret anymore!