This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Is the managed bean singleton? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Is the managed bean singleton?" Watch "Is the managed bean singleton?" New topic
Author

Is the managed bean singleton?

Ivan Lou
Greenhorn

Joined: Oct 08, 2008
Posts: 2
I'm beginner of learning jsf. I want to know whether the managed bean is singleton
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

Yes and no. It depends on how "single" you want it.

An application-scope managed bean is truly single. Only one of them per copy of the deployed webapp per server VM.

A session-scope managed bean is singleton on a per-user basis, but with multiple users, each user gets a unique and separate bean instance.

A request-scope bean is singleton on a per-request basis, but there can be lots of requests.

The "single"-ness of managed beans is determined by the fact that each bean ID in faces-config must be unique, so only one bean with that ID may exist in the context of its defined scope.

Only application scope is really singleton, the rest, like I said are unique, but only withing their contexts.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ivan Lou
Greenhorn

Joined: Oct 08, 2008
Posts: 2
Tim Holloway wrote:Yes and no. It depends on how "single" you want it.

An application-scope managed bean is truly single. Only one of them per copy of the deployed webapp per server VM.

A session-scope managed bean is singleton on a per-user basis, but with multiple users, each user gets a unique and separate bean instance.

A request-scope bean is singleton on a per-request basis, but there can be lots of requests.

The "single"-ness of managed beans is determined by the fact that each bean ID in faces-config must be unique, so only one bean with that ID may exist in the context of its defined scope.

Only application scope is really singleton, the rest, like I said are unique, but only withing their contexts.


Thank you, Tim Holloway.
 
jQuery in Action, 2nd edition
 
subject: Is the managed bean singleton?
 
Similar Threads
Take input from <h:inputText> in rich <modalPanel>
singleton
Injection - instance variable
how can i Pass an object from an Action to jsp page in struts?
Navigation does not work