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.
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.
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.
subject: JSF Listener discover the action method name