Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Application/Session Bean  RSS feed

 
nikos karanikos
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!