• 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

Application/Session Bean

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i create an application Bean how i can update it from another bean? Lets say application Bean has variable h=1 and i want to update from another bean and make it 2 how i can do it? And how i can access the value of a session bean from another bean?
Thank you
 
Saloon Keeper
Posts: 27752
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
JavaServer Faces is based on the Inversion of Control paradigm.

In IoC, you don't "go get" things, things are served up to you (using the managed bean's get/set methods).

When you define a Managed Bean, you can define (via faces-config.xml or annotations) Managed Properties. These Managed properties are other Managed Beans, which will be constructed if they don't already exist. As with simple values, the beans injected as Managed Properties are accessed via the target bean's set/get method.

So let's say you have 2 beans: beanA and beanB and that beanB is injected into beanA as as Managed Property. The beanA can invoke the getH() method on beanB to get the current value of H. If it wanted to increment beanB's "h" propertiy, the code then would imply be:


Which, of course, can be compacted down, although for easier debugging, I don't recommend actually crunching all the way down to a single statement.

The scope of beanB doesn't matter to beanA. JSF will automatically locate it. The only restriction is that you cannot inject objects of shorter-term scope into objects of longer-term scope. So if beanA is request, or session scope, beanB can be request, session or application scope, but not application scope. If beanA is session scope, beanB cannot be request scope, but it may be session or application scope.
reply
    Bookmark Topic Watch Topic
  • New Topic