Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-137

NumberValidator's error messages are localized, but parsing/formatting is not

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 3.0
    • 4.0.1
    • Framework
    • None
    • Operating System: Windows XP
      Platform: PC
    • 27652

    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>

      Attachments

        Activity

          People

            Unassigned Unassigned
            davide.orlandi.due@synago.it Davide Orlandi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: