aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/AbstractComponent.java
diff options
context:
space:
mode:
authorMika Murtojarvi <mika@vaadin.com>2014-12-08 17:57:38 +0200
committerMika Murtojarvi <mika@vaadin.com>2014-12-09 16:43:04 +0200
commitdb0403214329e77624caf6e592016a80e6195f6a (patch)
treebb5aff4d18910f556e888b942ae8a751a7f2b127 /server/src/com/vaadin/ui/AbstractComponent.java
parent12e5d620ab2ce885590a280d2c19e230cc083bb6 (diff)
downloadvaadin-framework-db0403214329e77624caf6e592016a80e6195f6a.tar.gz
vaadin-framework-db0403214329e77624caf6e592016a80e6195f6a.zip
Handle locale as a special case (#7749).
This cleans the generated html by not writing the locale to every tree node. Change-Id: I7a3c8300ee7726e22196c6cbc659fed8b78e3bd6
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractComponent.java')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java43
1 files changed, 42 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 11e24a306e..1b7eeadd87 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -938,6 +938,12 @@ public abstract class AbstractComponent extends AbstractClientConnector
} else {
explicitImmediateValue = null;
}
+ // handle locale
+ if (attr.hasKey("locale")) {
+ setLocale(getLocaleFromString(attr.get("locale")));
+ } else {
+ setLocale(null);
+ }
// handle width and height
readSize(attr, def);
// handle component error
@@ -965,6 +971,35 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
/**
+ * Constructs a Locale corresponding to the given string. The string should
+ * consist of one, two or three parts with '_' between the different parts
+ * if there is more than one part. The first part specifies the language,
+ * the second part the country and the third part the variant of the locale.
+ *
+ * @param localeString
+ * the locale specified as a string
+ * @return the Locale object corresponding to localeString
+ */
+ private Locale getLocaleFromString(String localeString) {
+ if (localeString == null) {
+ return null;
+ }
+ String[] parts = localeString.split("_");
+ if (parts.length > 3) {
+ throw new RuntimeException("Cannot parse the locale string: "
+ + localeString);
+ }
+ switch (parts.length) {
+ case 1:
+ return new Locale(parts[0]);
+ case 2:
+ return new Locale(parts[0], parts[1]);
+ default:
+ return new Locale(parts[0], parts[1], parts[2]);
+ }
+ }
+
+ /**
* Toggles responsiveness of this component.
*
* @since 7.4
@@ -1171,7 +1206,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
private static final String[] customAttributes = new String[] { "width",
"height", "debug-id", "error", "width-auto", "height-auto",
"width-full", "height-full", "size-auto", "size-full",
- "responsive", "immediate" };
+ "responsive", "immediate", "locale" };
/*
* (non-Javadoc)
@@ -1195,6 +1230,12 @@ public abstract class AbstractComponent extends AbstractClientConnector
if (explicitImmediateValue != null) {
design.attr("immediate", explicitImmediateValue.toString());
}
+ // handle locale
+ if (getLocale() != null
+ && (getParent() == null || !getLocale().equals(
+ getParent().getLocale()))) {
+ design.attr("locale", getLocale().toString());
+ }
// handle size
writeSize(attr, def);
// handle component error