File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

Call a method located in another bean from a bean

J Ram

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?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17247

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Call a method located in another bean from a bean
It's not a secret anymore!