Section 3.1.4 of the JSF 2.1 Specification says that all attributes of standard components are value expression enabled.
I want to assign a value expression to the action attribute of a commandButton:
<h:commandButton value="OK" action="#{myBean.valExp}" />
I also defined corresponding getValExp and setValExp methods in the bean's class.
However my JSF implementation (JBoss 6) takes that expression to be a method expression and thus yields a "method not found" error because there's no valExp()-method.
Am I doing something wrong or is the specification just too sloppy and actually doesn't mean all, but only the non method expression attributes? Or am I misunderstanding the spec?
[Remark: The reason for this question is no actual technical problem but me trying to understand the difference of value and method expressions.]
Value expressions are bound to properties which are exposed by public getter/setter methods.
This requires
public T getValue()
andpublic void setValue(T value)
methods. Note that the presence of aprivate T value;
property with literally exactly the same name is not mandatory. In pure output components like<h:outputText>
,<h:dataTable>
,<f:selectItems>
, etc, the setter method is also not mandatory.Method expressions are bound to non-getter/setter methods ("action" methods).
This requires a
public T submit()
method whereT
can eventually bevoid
and the method can eventually take additional arguments, depending on the attribute's method expression signature. You can read the exact details in the view declaration language documentation, for example the<h:inputText>
,<h:commandButton>
and<f:ajax>
ones. Here's an extract of theaction
andactionListener
attribute definitions of the<h:commandButton>
:Yes, I agree that the spec is somewhat sloppy in stating that all attributes support value expressions. Generally, they actually mean that all attributes support expression language as in
#{}
. From the other hand on, you can also interpret method expressions as if they are just "special" value expressions, although they are not exactly that. I've posted a spec issue report about this with the request to clear up some confusion: issue 1036.