This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Call a method located in another bean from a bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Call a method located in another bean from a bean" Watch "Call a method located in another bean from a bean" New topic
Author

Call a method located in another bean from a bean

J Ram
Greenhorn

Joined: Mar 16, 2013
Posts: 1
I am working on a project that has 3 beans at the moment, and one of them is a test harness for testing the database. Because my program is using Facades this test harness has to be in its own bean. In my diagnostics web page I attempt to pass a reference to the bean with the harness as such



where emailTestHarness is the name of the test harness bean Annotation @ManagedBean (name = "emailTestHarness")

Though when I push the button to call the method in my backing bean, I keep getting a null reference to the managed bean emailTestHarness. Is there a way I can gain a reference to the emailTestHarness bean using a POJO or am I just calling it wrong from the button?

Thaks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Welcome to the JavaRanch, J!

This is my morning to nag people. In JSF, you do not write the Controller. JSF provides the controllers for you. A backing bean is a Model.

The reason why your action expression isn't doing what you expect is that actions definitions and bean properties in the View are not executable code, they are EL references to attributes of a backing bean(s). So they shouldn't have parentheses, much less parameters.

JSF is based on Inversion of Control. The IoC way of getting one bean connected to another is to define it via a Managed Property, either in faces-config.xml or using the JSF2 ManagedProperty annotation. If you do that, JSF will automatically instantiate the referenced bean (if it doesn't already exist), and plug it into the target bean using the managed property's "set" method.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call a method located in another bean from a bean
 
Similar Threads
taking on the SCJD.....where do I start??
Remote bean lookup using SOAP
B&S starting up - GUI
B&S Database Design Structure
Using the Main method as a testing tool