• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

How to access method of another Bean

Posts: 6
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guyz!

I need to access the method of another bean and this method should use data from the calling bean.

Is this possible without creating a new instance of that method-bean?

Because im building a universal database-searchengine configured by xml and also the commandbuttons
are defined there. And i dont want that the guy who is using this engine has to change or add programm code!
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the scope of that bean which contains the method? If the scope is session, then you can get the bean instance from session object.
Saloon Keeper
Posts: 23284
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

I have you know we're all respectable professional professionals here. Just look at how dignified our Moose is!

JSF is based on the Inversion of Control concept. In IoC, the way for one bean to reference another bean is that the framework injects the referenced bean into the referencing bean using its POJO "set" method plus wiring rules which originally came from faces-config.xml but can (as of JSF2) also be constructed from @ManagedBean/@ManagedProperty annotations..

It sounds like you have a use case I've worked with a time or 2 myself. I present a search form, the user enters search criteria, hits the "search" button and results come back. Here's how I do it:

First, I have a backing bean for the search form. This is a short-lived bean and is one of the few cases in JSF where you can get away with using Request Scope.

The primary bean that will actually fire off the search and manage the search results is typically a session scope bean that has been wired into (injected) into the search form backing bean.

The action method of the search bean collects the search parameters, which are properties of the search bean and thus have been set by JSF when you clicked the "search" button. It can then invoke a search method on the search bean that was injected into the search form bean. It's up to the designer whether to inject the search properties as properties to the search bean or simply pass them as arguments to the search function (or mix-and-match, for that matter).

Once the search form's action processor has done its thing, it returns a navigation indicator that would either present the results of the search or some type of error page. Unless it would rather go somewhere else, instead.

It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic