((AbstractDecimalConverter<?>)converter).getNumberFormat(getLocale()).setGroupingUsed(false);
will set the flag on a NF instance which will be thrown away immediately.
Right, I should have tried that out first :/.
do formatting of values in NTF explicitly
What do you mean with this ?
I mean overriding getModelValue() and convertInput() and do formatting and
parsing independent of converters.
Sven
On 04/20/2012 05:41 PM, Martin Grigorov wrote:
Hi Sven,
On Fri, Apr 20, 2012 at 6:32 PM, Sven Meier<s...@meiers.net> wrote:
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.
What do you mean with this ?
Override #onComponentTag(), get the old value, remove all dots but the
last one and set the new value ?
I hope you mean something better than this ^^ :-)
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.
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 ?