You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rudy De Busscher <rd...@gmail.com> on 2011/03/06 14:14:51 UTC

Re: How do I get the Method EL Expression of actionListener in JSF 2.0?

@All, Leonardo,

It took me some time before I had time to try out your suggestion.

And I have to say, it works like a charm.  But it is deeply nested so
therefor, here are the steps that I took to get my hands on the expression
string of the actionListener attribute (within facelets)

- Create a custom TagHandlerDelegateFactory.  Define it in your faces config
file with <application><tag-handler-delegate-factory>.  The constructor
takes one parameter, another TagHandlerDelegateFactory.  All methods
delegate to the constructor received object.  The
createComponentHandlerDelegate method returns a wrapped version of a
TagHandlerDelegate.
- wrapped TagHandlerDelegate -> within createMetaRuleset we add a new
MetaRule when ActionSource.class.isAssignableFrom(type).
- new MetaRule -> within applyRule method we return a new Metadata when the
name equals actionListener (the attribute).  El expression can be retrieved
by attribute.getValue().
- new Metadata -> within applyMetadata method, we put the EL expression on
the attributes of the UIComponent.

Then, you have always access to the expression string by looking at the
attributes of the component.

I have tested the approach with Myfaces and Mojarra.

Code is probably better to understand, so you will find it here (1)

(1) https://bitbucket.org/os890/extval-addons/overview in the directory
bean_validation_module\group_actions\forJSF20

Thx
Regards
Rudy

On 11 February 2011 10:35, Rudy De Busscher <rd...@gmail.com> wrote:

> Hi Leonardo,
>
> Thanks for pointing me into a direction for a solution.  Try it as soon as
> I have time for it.
>
> Thx
> Rudy.
>
>
> On 11 February 2011 06:38, Leonardo Uribe <lu...@gmail.com> wrote:
>
>> Hi
>>
>> Sorry for the late response. The problem is jsp uses
>> UICommand.setActionListener method, but in facelets things are different.
>>
>> Look this class:
>>
>>
>> http://svn.apache.org/repos/asf/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ActionSourceRule.java
>>
>> If the target is instance of ActionSource, setActionListener is used, but
>> if
>> is ActionSource2, the listener is added through addActionListener and use
>> a
>> wrapper (javax.faces.event.MethodExpressionActionListener).
>>
>> The problem is there is no underlying MethodBinding in this case.
>>
>> The solution could be create a custom ComponentTagHandlerDelegate with a
>> special rule for ActionSource. I think it is the right moment to get the
>> EL
>> expression.
>>
>> regards,
>>
>> Leonardo
>>
>> 2011/2/7 Rudy De Busscher <rd...@gmail.com>
>>
>> > Hi all,
>> >
>> > For an ExtVal-addon I need to have access to the expression string of
>> the
>> > actionListener property of a command button.
>> >
>> > So when i have
>> > *<h:commandButton id="check" value="Validate"
>> > actionListener="#{personBean.someActionListener}"/>*
>> > I need #{personBean.someActionListener}.
>> >
>> > In JSF 1.X, you could get the MethodBinding by calling
>> > *actionCommand.getActionListener() *
>> > but now it returns null. *The method is deprecated but maybe this is a
>> bug
>> > that the old behaviour isn't respected?*
>> >
>> > I can access the actionListener by calling
>> > *actionCommand.getActionListeners()*
>> > but then I get the interface object back and not the underlying
>> > MethodBinding.
>> >
>> > Anyone an idea?
>> >
>> > Thx
>> > Rudy.
>> >
>>
>
>