Details
Description
Error messages from NumberValidator are formatted using locale settings (since
they are built from MessageFormat.format()) but parsing and formatting is not.
So, for example, if the minimum value constraint is set to 12345, an user
typing "5000" in a ValidField would get this error:
"test numeric field must not be smaller than 12,345."
And typing "12,345" (pasting exactly from the error message) he would get:
"test numeric field must be a numeric value."
This can be quite misleading for users, especially in non-english locales: an
italian ResourceBundle of ValidationStrings would display 12345 as "12.345"
(yes, with the dot – stupid locale rules ).
Solutions: NumberValidator should format/parse using a localized NumberFormat
(not so easy) or (easier) minimum and maximum should be toString()ed before
passing them to formatString().
Tested code (using Tapestry 3.0 beta 4 and Tomcat 5.0.18):
— Home.page —
<page-specification class="org.apache.tapestry.html.BasePage">
<property-specification name="numericValue" type="java.lang.Integer" />
<bean name="validator" class="org.apache.tapestry.valid.NumberValidator">
<set-property name="minimum" expression="12345" />
</bean>
<bean name="delegate"
class="org.apache.tapestry.valid.ValidationDelegate" />
</page-specification>
— Home.html —
<html><body>
<div jwcid="@Delegator" delegate="ognl:beans.delegate.firstError" />
<form jwcid="@Form" delegate="ognl:beans.delegate">
<input jwcid="@ValidField" validator="ognl:beans.validator"
displayName="test numeric field" value="ognl:numericValue" />
<input jwcid="@Submit" />
</form>
</body></html>