Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How To initialize one bean from another bean

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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




 
Greenhorn
Posts: 12
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 28053
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic