I have an h:commandLink
that calls a method that changes a property bound to a radio input.
I also have a text input on the same form with some validation (required=true).
If I leave the text input blank, and click on h:commandLink
with execute="@this
, the radio button updates from the model property as expected, because the text input is never processed and validation never fires.
However, if first I click on a different h:commandLink
with execute="@form"
, then the link with execute="@this"
, the validation messages go away but the radio button value does not update from the model even though the UIInput for the radio button was never in an invalid state.
I'm finding it annoying that the execute="@this"
behaves differently depending on what I had done previously, when my intent with @this
was to force everything to update from the model and ignore any submitted values from the components.
I suspect what's happening is something like this:
- with
@form
, radio button and text are both processed. - Radio button is valid so
localValue
is set - Process validations phase fails overall because of invalid text input, so
localValue
remains set and does not get cleared or propagate tovalue
- the only way out of this is to explicitly call
resetValue()
or to re-process the component in question (e.g.,execute="@this radio"
) to clear outlocalValue
and then allow refreshing from bean.
My questions are:
- is my understanding of the lifecycle correct?
- Am I doing something wrong, or is this one of the annoying-by design things about JSF?
It feels like this may just be another example of this question
How can I populate a text field using PrimeFaces AJAX after validation errors occur?
Unfortunately I feel like I'm finding lots of those lately. :-(
Code example below:
<h:form>
<h:messages/>
Radio =
<h:selectOneRadio value="#{testBean.radioValue}" id="radio" binding="#{radio}">
<f:selectItem itemValue="foo" itemLabel="Foo"/>
<f:selectItem itemValue="bar" itemLabel="Bar"/>
</h:selectOneRadio>
<br></br>
radio bean value = <h:outputText value="#{testBean.radioValue}"/>
<br></br>
radio UIInput localValue = <h:outputText value="#{radio.localValue}"/>
<br></br>
radio UIInput value = <h:outputText value="#{radio.value}"/>
<br></br>
String w/validation = <h:inputText value="#{testBean.stringValue}" required="true" />
<br></br>
<ul>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @form">
<f:ajax render="@form" execute="@form"/>
</h:commandLink>
</li>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @this">
<f:ajax render="@form" execute="@this"/>
</h:commandLink>
</li>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @this radio">
<f:ajax render="@form" execute="@this radio"/>
</h:commandLink>
</li>
</ul>
</h:form>
And this bean:
@ManagedBean
@ViewScoped
public class TestBean {
private String radioValue = "foo";
private String stringValue;
public void changeRadioValue() {
radioValue = "bar";
}
// + getters/setters
}