• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To initialize one bean from another bean

 
Arvind Purohit
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic