1

As @BalusC pointed here How to pass an iterated parameter via ajax to a backing bean method, it is possible to pass whole objects along as arguments in EL.

in JSF2, using action=#{bean.method(object)} works, but I don't understand how.

Documentations of various versions of JSF (JSF doc) say this about the action attrubute:

The expression must evaluate to a public method that takes no parameters

So why action=#{bean.method(object)} works? Is it realable to use this technique, or it could not work in future releases?

EDIT:

Plus, as @vasil-lukach said, documentation of EL permits it. In fact, as said in (EL doc), with EL2.2, one can use:

<h:commandButton action="#{trader.buy('SOMESTOCK')}" value="buy"/>

Are these two specifications in agreement?

Community
  • 1
  • 1
Antonio Ragagnin
  • 2,278
  • 4
  • 24
  • 39
  • 1
    It works not in JSF2, but with EL2.2. Try it with JSF 2.1 and EL2.1, and you will see error. – Vasil Lukach Mar 26 '14 at 17:47
  • Thanks @VasilLukach . In the EL2.2 http://docs.oracle.com/javaee/6/tutorial/doc/bnahu.html#gjhbz they even use an example with a parametrized call in an `action`. Then are these two standards in agreement? – Antonio Ragagnin Mar 26 '14 at 20:17

1 Answers1

1

There are two versions of the method that is invoked. The first is invoked if the EL expression does not contain any parameters at all. In this case the method that is invoked must not have any parameters indeed. In the case of the actionListener it must have exactly the prescribed event parameter.

If you provide parameters, then those parameters are bound by the EL implementation itself and a method in the bean corresponding with those parameters will be called. In that case any parameters that JSF itself would otherwise have provided (like the event instance) are lost.

dexter meyers
  • 2,798
  • 2
  • 18
  • 22