Value expressions are bound to properties which are exposed by public getter/setter methods.
<h:inputText value="#{bean.value}" />
This requires public T getValue()
and public void setValue(T value)
methods. Note that the presence of a private 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).
<h:commandButton value="submit" action="#{bean.submit}" />
This requires a public T submit()
method where T
can eventually be void
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 the action
and actionListener
attribute definitions of the <h:commandButton>
:
Name: action
Type: javax.el.MethodExpression (signature must match java.lang.Object
action())
Description: MethodExpression representing the application action to invoke when
this component is activated by the user. The expression must
evaluate to a public method that takes no parameters, and returns an
Object (the toString() of which is called to derive the logical
outcome) which is passed to the NavigationHandler for this
application.
Name: actionListener
Type: javax.el.MethodExpression (signature must match void
actionListener(javax.faces.event.ActionEvent))
Description: MethodExpression representing an action listener method that will be
notified when this component is activated by the user. The
expression must evaluate to a public method that takes an
ActionEvent parameter, with a return type of void, or to a public
method that takes no arguments with a return type of void. In the
latter case, the method has no way of easily knowing where the event
came from, but this can be useful in cases where a notification is
needed that "some action happened".
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.
<h:inputText value="#{myBean.invoke(string)}" />
– Latarsha