This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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 F. Borges
Greenhorn

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: 15961
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To initialize one bean from another bean
 
Similar Threads
How can I set bean property in JSF page?!
Struts : Accessing a javabean inside a JSP
UseBean, scope question.
include directive confusion
How to implement Session Tracking