aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/declarative
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-03-18 15:26:39 +0200
committerVaadin Code Review <review@vaadin.com>2015-03-20 09:21:23 +0000
commit7d4de11c54060286bbc7adfeefa2891f3a461b1d (patch)
treeb5bf9a5f27371baf8602d448c7a5d8a32569c522 /server/src/com/vaadin/ui/declarative
parent79db1a1464e37828ca165f160486e53d877710ed (diff)
downloadvaadin-framework-7d4de11c54060286bbc7adfeefa2891f3a461b1d.tar.gz
vaadin-framework-7d4de11c54060286bbc7adfeefa2891f3a461b1d.zip
Fix Declarative support for primitive float and double properties (#17204)
Also improve tests. Change-Id: I99e064c931770fb8af511ea5c8e2c7fc2da2464e
Diffstat (limited to 'server/src/com/vaadin/ui/declarative')
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignFormatter.java25
-rw-r--r--server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java5
2 files changed, 19 insertions, 11 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
index d2fbf2c765..cc5071fe9d 100644
--- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java
+++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
@@ -19,6 +19,7 @@ import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
@@ -110,22 +111,28 @@ public class DesignFormatter implements Serializable {
converterMap.put(boolean.class, booleanConverter);
// floats and doubles use formatters
- DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale(
- "en_US"));
+ final DecimalFormatSymbols symbols = new DecimalFormatSymbols(
+ new Locale("en_US"));
final DecimalFormat fmt = new DecimalFormat("0.###", symbols);
fmt.setGroupingUsed(false);
- converterMap.put(Float.class, new StringToFloatConverter() {
+
+ Converter<String, ?> floatConverter = new StringToFloatConverter() {
@Override
- protected java.text.NumberFormat getFormat(Locale locale) {
+ protected NumberFormat getFormat(Locale locale) {
return fmt;
};
- });
- converterMap.put(Double.class, new StringToDoubleConverter() {
+ };
+ converterMap.put(Float.class, floatConverter);
+ converterMap.put(float.class, floatConverter);
+
+ Converter<String, ?> doubleConverter = new StringToDoubleConverter() {
@Override
- protected java.text.NumberFormat getFormat(Locale locale) {
+ protected NumberFormat getFormat(Locale locale) {
return fmt;
};
- });
+ };
+ converterMap.put(Double.class, doubleConverter);
+ converterMap.put(double.class, doubleConverter);
// strings do nothing
converterMap.put(String.class, new Converter<String, String>() {
@@ -169,7 +176,7 @@ public class DesignFormatter implements Serializable {
};
converterMap.put(Character.class, charConverter);
- converterMap.put(Character.TYPE, charConverter);
+ converterMap.put(char.class, charConverter);
converterMap.put(Date.class, new DesignDateConverter());
converterMap.put(ShortcutAction.class,
diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java
index d80119bea1..0c6cf55bed 100644
--- a/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java
+++ b/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java
@@ -64,7 +64,8 @@ public class DesignToStringConverter<TYPE> implements Converter<String, TYPE> {
* must be public and static method that returns an object of
* passed type.
*/
- public DesignToStringConverter(Class<? extends TYPE> type, String staticMethodName) {
+ public DesignToStringConverter(Class<? extends TYPE> type,
+ String staticMethodName) {
this.type = type;
this.staticMethodName = staticMethodName;
}
@@ -81,7 +82,7 @@ public class DesignToStringConverter<TYPE> implements Converter<String, TYPE> {
} catch (IllegalArgumentException e) {
throw new Converter.ConversionException(e);
} catch (InvocationTargetException e) {
- throw new Converter.ConversionException(e);
+ throw new Converter.ConversionException(e.getCause());
} catch (NoSuchMethodException e) {
throw new Converter.ConversionException(e);
} catch (SecurityException e) {