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