aspose file tools*
The moose likes JSF and the fly likes Project design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Project design" Watch "Project design" New topic
Author

Project design

Fernando Guerrero
Greenhorn

Joined: Apr 26, 2011
Posts: 14

Hello

I am designing a JSF application, in this application I have 5 beans and I need to share information between them. I tough that implementing a singleton class would help me, because I want that only one object of this singleton class is created and we can use it to share information between the beans, Every time an user log in into the system application, one Bean1 object is created, one Bean2 object , several Bean3 objects, several Bean4 object and one Bean5 object. The huge problem that I have is, as this application is a JSF application, several users can log in into the system at the same time, every time a user log in, the beans object are created for each user (Each user has a different bean copy) but only one singleton object is created, only one for all the different users, all the user share the same singleton object, this is creating a huge problem because the data from one user overrides the data from other user!!!

I still need to create and object that can share information between the beans, but I need that each user has a different copy.

What design patter would you suggest me? or what kind of modification can I do to my actual design ???

Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I can't name a design pattern, but if each user needs a unique copy of a bean, then they should not be singletons, they should be session beans, since each user gets a discrete session. Singleton beans would normally be used at application scope, although because of the way JSF constructs beans, actually making a true singleton for an application scope object is usually overkill.

JSF is based on the Inversion of Control paradigm. In IoC, you don't connect things together via logic, you have a framework that manages the connections. In the case of JSF, that's the Managed Bean facility. By proper coding of the faces-config.xml file (or annotation equivalences), you can inject beans into other beans.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Project design