wood burning stoves 2.0
The moose likes JSF and the fly likes How To initialize one bean from another bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How To initialize one bean from another bean" Watch "How To initialize one bean from another bean" New topic

How To initialize one bean from another bean

Arvind Purohit
Ranch Hand

Joined: Jun 18, 2010
Posts: 43
Hi All
I am using JSF 2.0 , I have two beans UserBean ( Request Scope ) and UserInfoBean( Session Scope ).
I want to know how can initialize UserInfoBean from one method of UserBean( Request Scope ) so that i can access it from anywhere.

I also want to know performance wise which is better 1. Put a bean as session bean 2. put different different variable in session individually.
Thanks A Lot

Emmanuel Borges

Joined: Mar 25, 2011
Posts: 12

You have to inject the UserInfoBean into UserBean using the @ManagedProperty Annotation.

Now you can use the UserInfoBean, 'userInf', anywhere inside UserBean.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

How you arrange your beans in a session is going to make essentially no difference in performance. Besides, premature optimization is not a good idea, since - and I speak from long experience - the actual inefficiences you'll find when you run performance measurements are almost never where people "thought" "knew" they would be. A clean architecture is easier to optimize than an "optimized" architecture is.

JSF will not let you inject a Request object into a Session object, because the actual request object itself is transient. The rule is that you can only inject an object whose lifespan is the same or longer as the object being injected into. So you can back-inject the session bean into the request bean, but not the other way around.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: How To initialize one bean from another bean
It's not a secret anymore!