I have this simple facelets page:
<!DOCTYPE html>
<html xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Index</title>
</h:head>
<h:body>
<h:form>
<h:inputText id="firstname" value="#{fooBar.firstname}">
<f:ajax event="keyup" render="echo" execute="myCommandButton"/>
</h:inputText>
<h:commandButton value="Submit" action="#{fooBar.fooBarAction()}" id="myCommandButton"/>
</h:form>
<br/>
<h:outputText id="echo" value="#{fooBar.firstname}"/>
</h:body>
</html>
and the Foobar bean is as follows:
@ManagedBean
@ApplicationScoped
public class FooBar {
private String firstname;
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getFirstname() {
return firstname;
}
public void fooBarAction() {
System.out.println("Foo bar action being executed!!!");
}
}
So my expectation is to see the text Foo bar action being executed whenever I type something in the inputText field, but it is not the case. What am I missing?
Edit: Why am I expecting this behavior? I am studying the book Core JavaServer Faces and in the book it is noted that:
JSF 2.0 splits the JSF life cycle into two parts: execute and render.
Execute consists of: Restore View -> Apply Request Values -> Process Validations -> Update Model Values -> Invoke Application
When JSF executes a component on the server, it:
-Converts and validates the component 's value (if the component is an input).
-Pushes valid input values to the model (if the component is wired to a bean property).
-Executes actions and action listeners (if the component is an action).
So here, myCommandButton should be executed, isn 't it? And execution of a component means its action to be executed?
Edit #2
This quotation is from JavaServer Faces Complete Reference
If listener is not specified, the only action that will be invoked during the Invoke Application phase will be the one that corresponds to an ActionSource component listed in the execute attribute.
So as far as I understand, in my example, I have a component that implements the ActionSource interface (myCommandButton), and the action attribute of this component should be executed. But it is not?