myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Korherr <jakob.korh...@gmail.com>
Subject Re: access MethodExpression from actionListener
Date Tue, 12 Jan 2010 18:23:51 GMT
Hi Michael,

Taking a short look at MethodExpressionActionListener, there are no getters
and the instance fields are private.. One way to get the original
MethodExpression is (as you suggested) to patch this class locally..

Another would be (although poor) to use the saveState()-method to get the
ActionListener's state. This is usually an Object array with most of its
instance variables. Then you could extract the MethodExpression from the
Object array.

..or you could use reflection to access the private field, but that's also
not very "beautiful".

Hope this helps!

Regards,
Jakob

2010/1/12 Michael Heinen <michael.heinen@recommind.com>

> Hi,
>
> I use a global action-listener defined in faces-config via the
> action-listener tag to log called actions/actionsListeners.
> With JSF 1.1 I used following code:
>
> private void storeCalledAction(ActionEvent actionEvent){
>  ActionSource actionSource = (ActionSource) actionEvent.getComponent();
>  //1. check for action listener
>  MethodBinding methodBinding = actionSource.getActionListener();
>  if (methodBinding == null){
>    //2. check for action
>    methodBinding = actionSource.getAction();
>  }
>  if (methodBinding != null){
>    action = methodBinding.getExpressionString();
>    ...
>
> MethodBinding is deprecated in JSF1.2 and also null for actionListeners.
> Therefore I changed ActionSource to ActionSource2 and MethodBinding to
> MethodExpression.
>
> private void storeCalledAction(final ActionEvent actionEvent){
>  ActionSource2 actionSource = (ActionSource2) actionEvent.getComponent();
>  MethodExpression methodExpression = actionSource.getActionExpression();
>
>  if (methodExpression==null){
>    ActionListener[] actionListeners = actionSource.getActionListeners();
>    if (actionListeners!=null && actionListeners.length>0){
>      ActionListener lastActionListener =
> actionListeners[actionListeners.length-1];
>      //???? And now???
>    }
>  }
>
> How can I access the methodExpression of the (now nested) ActionListeners?
> They are of type javax.faces.event.MethodExpressionActionListener but there
> is no getter available.
>
> Do I have to patch MethodExpressionActionListener locally and add a getter
> or is there an official alternative?
>
> Michael
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message