Search code examples
jsf-2elrendered-attribute

How come JSF 2.x with EL 2.2 allows MethodExpression in place for ValueExpression?


I am seeing several questions asking how to pass parameters to JSF methods. With EL2.2 and servlet 3.0, it enables user to pass parameters into a method call. One example: How to pass an argument to method from rendered h:outputText? The question is: In JSF 2.x, each tag attribute is supposed to take either ValueExpression or MethodExpression. In the linked example, "rendered" is supposed to only take ValueExpression. However I do see it still works with MethodExpression if we put () to make it clear it is a method call instead of a property. Is this something the JSF 2.x spec just messed up or am I missing something?


Solution

  • Using the new EL 2.2 invoking-methods-with-arguments syntax in a value expression doesn't automagically make it a method expression or something. It's still a value expression. A value expression uses the returned value of the given EL expression as a value. A method expression invokes the given EL expression upon an action event associated with the component.

    Whether the EL expression at its own invokes a property getter method or an arbitrary method with arguments really doesn't matter as to how the EL expression at the whole is treated.