import java.util.concurrent.ConcurrentHashMap;
import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.StringToBigDecimalConverter;
import com.vaadin.data.util.converter.StringToDoubleConverter;
import com.vaadin.data.util.converter.StringToFloatConverter;
import com.vaadin.event.ShortcutAction;
*/
protected void mapDefaultTypes() {
// numbers use standard toString/valueOf approach
- for (Class<?> c : new Class<?>[] { Integer.class, Byte.class,
- Short.class, Long.class, BigDecimal.class }) {
+ for (Class<?> c : new Class<?>[] { Byte.class, Short.class,
+ Integer.class, Long.class }) {
DesignToStringConverter<?> conv = new DesignToStringConverter(c);
converterMap.put(c, conv);
try {
converterMap.put(Double.class, doubleConverter);
converterMap.put(double.class, doubleConverter);
+ final DecimalFormat bigDecimalFmt = new DecimalFormat("0.###", symbols);
+ bigDecimalFmt.setGroupingUsed(false);
+ bigDecimalFmt.setParseBigDecimal(true);
+ converterMap.put(BigDecimal.class, new StringToBigDecimalConverter() {
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ return bigDecimalFmt;
+ };
+ });
+
// strings do nothing
converterMap.put(String.class, new Converter<String, String>() {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
byte.class, short.class, int.class, long.class, float.class,
double.class, Boolean.class, Character.class, Byte.class,
Short.class, Integer.class, Long.class, Float.class,
- Double.class, String.class, ShortcutAction.class, Date.class,
- FileResource.class, ExternalResource.class,
- ThemeResource.class, Resource.class, TimeZone.class }) {
+ Double.class, BigDecimal.class, String.class,
+ ShortcutAction.class, Date.class, FileResource.class,
+ ExternalResource.class, ThemeResource.class, Resource.class,
+ TimeZone.class }) {
assertTrue("not supported " + type.getSimpleName(),
formatter.canConvert(type));
}
}
+ @Test
+ public void testBigDecimal() {
+ BigDecimal bd = new BigDecimal("123456789123456789.123456789123456789");
+ assertEquals("123456789123456789.123", formatter.format(bd));
+ assertEquals(bd, formatter.parse(
+ "123456789123456789.123456789123456789", BigDecimal.class));
+ }
+
@Test
public void testChar() {
char c = '\uABCD';