• 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

Call a method located in another bean from a bean

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27764
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
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic