wicket-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sven Meier <s...@meiers.net>
Subject Re: Number formats in numeric converters
Date Fri, 20 Apr 2012 15:32:53 GMT
Hi Martin,

IMHO we shouldn't touch grouping in display of numbers (e.g. in labels), 
so -1 for changing it globally.

BTW if somebody registered his own converter for numbers, he would again 
have to take care of grouping by himself.

Instead we could
3)
Skip converters and do formatting of values in NTF explicitly, since 
we're not actually converting numbers for display but formatting them to 
their technical representation.

4)
Stay with converters but add a safety net in NTF:

     @Override
     public <C> IConverter<C> getConverter(Class<C> type)
     {
         IConverter<C> converter = super.getConverter(type);
         if (converter instanceof AbstractDecimalConverter<?>)
         {
             
((AbstractDecimalConverter<?>)converter).getNumberFormat(getLocale()).setGroupingUsed(
                 false);
         }
         return converter;
     }

Sven


On 04/20/2012 02:56 PM, Martin Grigorov wrote:
> Hi,
>
> Working on https://issues.apache.org/jira/browse/WICKET-4501 I see
> that it is quite hard to set custom number format for the converter
> used by NumberTextField (NTF).
> The problem in 4501 is that when T in NumberTextField<T>  is Float,
> Double or BigDecimal the produced value by #convertToString() uses
> grouping and value like 12345.987 is actually
> rendered as 12.345.987 which is not supported by
> http://dev.w3.org/html5/markup/datatypes.html#common.data.float
> To solve the problem all I need is:
> numberFormat.setGroupingUsed(false)
>
> There are two ways to do that:
> 1) Add a note in the javadoc of NumberTF explaining that the user
> should override #getConverter(Class) and return an instance of the
> most suitable converter (like FloatConverter or BigDecimalConverter)
> and override its #getNumberFormat() that does:
> @Override public NumberFormat getNumberFormat() {
>    NumberFormat format = super.getNumberFormat();
>    format.setGroupingUsed(false);
>    return format;
> }
>
> Cons: the app developer should do this himself. Otherwise the browser
> will show<input type="number" value="12.345.987"/>  as empty. I.e. the
> user will believe there is no value set
>
> 2) Add "format.setGroupingUsed(false);" in
> org.apache.wicket.util.convert.converter.AbstractDecimalConverter#setNumberFormat(Locale,
> NumberFormat)
> Cons: this is a *global* behavior change that will fix the problem for
> NTF but will break the formatting for every other place where
> AbstractDecimalConverter is used.
>
> Do you see better solutions ?
>


Mime
View raw message