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 ?
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com