Hi Christoph,

>It wouldn't be a no-op if you stored the modified NumberFormat in the cache:

this would change the grouping for all numberformats cloned in succession by the converter, wouldn't it?
This is the same as changing the grouping globally.

Sven

On 04/22/2012 05:58 PM, Christoph Leiter wrote:
On 20.04.2012 17:41, Martin Grigorov wrote:
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;
    }

This wont work because numeric converters keep a cache of number
formats per locale and return a fresh clone on each getNumberFormat()
call.
I.e. the code above will set the flag on a NF instance which will be thrown
away immediately.

It wouldn't be a no-op if you stored the modified NumberFormat in the cache:

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

As far as I can tell this has no unintended global consequences... A normal TextField<BigDecimal> still displays the number with grouping.


Christoph

Reply via email to