| 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: 14456
|
|
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.
|
 |
 |
|
|
subject: Call a method located in another bean from a bean
|
|
|