Wicket
  1. Wicket
  2. WICKET-1254

Binding to a BigDecimal don't honor browser locale

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.0-rc2
    • Fix Version/s: 1.3.1
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      Windows XP, Firefox 2.0.0.11, tomcat-5.5.25, Java 1.6.0_03

      Description

      Binding from a TextField to a BigDecimal property does not honor the Locale used by the browser.

      With the pt_BR locale configured in Firefox, binding "0,25" to a Double works as expected giving 0.25 value, but to a BigDecimal it gives the error "'0,25' não é um BigDecimal válido."

      It is a major problem with localized applications.

        Activity

        Hide
        Frank Bille Jensen added a comment -

        Don't set fix version, if it's not actually fixed in that version.

        Show
        Frank Bille Jensen added a comment - Don't set fix version, if it's not actually fixed in that version.
        Hide
        Gerolf Seitz added a comment -

        you can easily create a subclass of AbstractNumberConverter and do the conversion yourself with DecimalFormat.

        i agree that this might be confusing as it "somehow" works.
        i'd say we should either provide a BigDecimalConverter as default or remove the "broken" magic default conversion (which is pretty much impossible right now)

        what do others think?

        Show
        Gerolf Seitz added a comment - you can easily create a subclass of AbstractNumberConverter and do the conversion yourself with DecimalFormat. i agree that this might be confusing as it "somehow" works. i'd say we should either provide a BigDecimalConverter as default or remove the "broken" magic default conversion (which is pretty much impossible right now) what do others think?
        Hide
        Eduardo Issao Ito added a comment -

        Yes, it is easy to create a BigDecimalConverter, but as it is a type provided by Java itself, it makes sense to include such a converter in core Wicket... We should apply the "Principle of Least Surprise"!

        I used the converter below and it worked fine:

        class BigDecimalConverter extends AbstractDecimalConverter {

        protected Class getTargetType()

        { return BigDecimal.class; }

        public Object convertToObject(String value, Locale locale) {
        if (value == null || value.trim().equals(""))
        return null;

        NumberFormat format = getNumberFormat(locale);
        try

        { return format.parse(value); }

        catch (Exception e)

        { throw newConversionException("Cannot parse '" + value + "' using format " + format, value, locale).setFormat(format); }

        }
        }

        Show
        Eduardo Issao Ito added a comment - Yes, it is easy to create a BigDecimalConverter, but as it is a type provided by Java itself, it makes sense to include such a converter in core Wicket... We should apply the "Principle of Least Surprise"! I used the converter below and it worked fine: class BigDecimalConverter extends AbstractDecimalConverter { protected Class getTargetType() { return BigDecimal.class; } public Object convertToObject(String value, Locale locale) { if (value == null || value.trim().equals("")) return null; NumberFormat format = getNumberFormat(locale); try { return format.parse(value); } catch (Exception e) { throw newConversionException("Cannot parse '" + value + "' using format " + format, value, locale).setFormat(format); } } }

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Eduardo Issao Ito
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development