Just when I thought I had understood immediate... *sigh*
Consider the following JSF page:
<h:inputText value=\"#{testBean.text}\" required=\"true\" />
<h:commandButton actionListener=\"#{testBean.doFoo}\" value=\"Do Foo\" />
<h:commandButton immediate=\"true\" actionListener=\"#{testBean.doBar}\" value=\"Do Bar\" /><br />
<h:outputText value=\"#{testBean.didSomething}\" />
And this backing bean:
public class TestBean {
private String didSomething = \"Nothing done yet\";
// + getter
public void doFoo() {
didSomething = \"Did foo!\";
}
public void doBar() {
didSomething = \"Did bar!\";
}
From all I read about immediate I would expect the following:
When trying to do foo while not providing a value for the input field, the action is never executed because during
processValidationsPhase
an error occurs, resulting in the page to be re-rendered directly after this phase with an error message. The value of thedidSomething
remains unchanged. (This works as expected)When trying to do bar while not providing a value for the input field, the action is executed during
applyRequestValuesPhase
because of the immediate attribute. The variabledidSomething
is changed. (This works as expected)
On what happens next, this description states:
\"A null return value (as outcome of the action method) causes processing to continue as normal, ie non-immediate components are validated then update-model is executed (if no validation errors occurred). For an action listener method that returns void, it is necessary to call facesContext.renderResponse(); if the normal flow is not desired.\"
From this I had the idea that processing continues as normal (as my action method does neither return an outcome nor force renderResponse()
), resulting in the same validation error. Only difference would be that it occurs after setting didSomething
. However, this does not happen. Instead, it feels like the site still skips all remaining phases, with the input field not being touched. It re-renders without error message.
Can someone explain to me where my understanding of how this works is amiss?