• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 27762
196
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.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic