• 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

JSF Listener discover the action method name

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.

I've been struggling to get the name of the method that started invoking my BackingBean.
I'm using a PhaseListener who is listening to invoke_app phase id.
Through this approach, I'd like to know the name of the method that fired this event.

I've been searching for the method name within the FacesContext , Application and ExternalContext but with no success.
I also tried to use reflection to get access to the "events" attribute of UIViewRoot (I saw inside the myfaces sourcecode). But... no success again...

Anybody know any way to achieve this? either by reflection or better using the API without any hacking.

The source code using reflection with no success



Thanks
 
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
First question: Why? What benefit will you have from knowing the method name?

Second question: Huh? The action method is fired directly from JSF. I should hope that it already knows who it is.
 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tim Holloway!

Thanks for replying.
I need to do this because of a really specific scenario.
The project I'm working on use the JSF 1.1 spec and I need to invoke dynamically some methods from backing beans which implements some kind of interface.
But there is some times that a specific method cannot be executed dynamically and I'd like to detect when it was invoked.

I can't change this architecture, so I'd like to use some JSF hooks to achieve that.

But, I can get the "events" attribute now from the UIViewRoot.
I forgot to use the code below before retrieving the value of the attribute.



I know that I'm breaking this encapsulation but I don't have any idea to deal with this so specific scenario.

Thanks
 
Tim Holloway
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
Well, it's hard for me to imagine what exactly it is you're dealing with, but I doubt that this is really a problem that needs JSF to solve it.

An Interface declaration is a contract that defines a specific set of methods that an implementing class will realize. So if you attach a bean - any bean, not just a JSF bean - to an invoking method (such as an action method) and that bean does implement that interface, then there will be some implementation of each of those interface methods. Maybe a dummy or stub, but at least something.

On the other hand, if the object in question doesn't define a contract (interface), then you have to go one step further and introspect the target object's method collection to see if it implements the method you need.

Introspection is part of the basic java.lang package set. You don't need JSF to introspect a bean, but JSF uses introspection internally to do things like locate and call property access methods and action methods.

Actually, JSF uses an extended Apache package called "beanutils". You can find it - and its documentation at the jakarta.apache.org website. It may be in one of the commons library collections these days. BeanUtils isn't essential for introspection, but it adds additional introspective capabilities that you might find useful.

I've done this kind of stuff many times. It's not really all that hard.
 
reply
    Bookmark Topic Watch Topic
  • New Topic