Dear all,
Lately I discovered the following strange behavior in my apps. I
am using MyFaces Core 1.1.3 and Tomahawk 1.1.3. Here is a test scenario:
I have a session scoped managed bean, and a form with 3 text fields, one
bound to some Integer value and two bound to String values the last of which is
required:
<h:messages/>
<h:form>
<h:inputText value="#{helloBean.testInteger}"/>
<h:inputText value="#{helloBean.testString1}"/>
<h:inputText value="#{helloBean.testString2}" required="true"/>
<h:commandButton value="Submit!"/>
</h:form>
<h:panelGrid columns="1">
<h:outputText value="integer: #{helloBean.testInteger}"/>
<h:outputText value="string1 : #{helloBean.testString1}"/>
<h:outputText value="string2: #{helloBean.testString2}"/>
</h:panelGrid>
When I first run this simple example all the fields are empty. I fill them in
with the values “1”, “aaa”, and “bbb” respectively and hit the submit button
and the values appear on the table below the form.
I then clear the fields and resubmit the form which will cause a validation
error message to be displayed, since the last of the 3 fields is required. The
values on the table will correctly retain their previous values as the model
has not been updated. However although the 2 string fields will display their
last submitted value correctly (i.e. they will be blank), the number field will
have re-acquired the bean value (i.e. the value “1”). This occurs because the
getValue() method will only return the component’s local value if it is not
null.
Probably this is no news to you, but could someone please clarify if this is
the correct behavior according to the spec? I’ve also tested it with Sun’s RI
and got the same behavior…
Also there was an issue at the JIRA that seemed related
(http://issues.apache.org/jira/browse/MYFACES-187), but it has been closed.
In my opinion the getValue() method should check if the local value has been
set and return it no matter if it is null. I think it looks strange if the user
to submit a form of string, number, date fields, and have only the string
fields remember their last submitted value when a validation error occurs….
Thanx for reading. Any thoughts welcome.
Mario