Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top