aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-10-24 11:32:16 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-26 05:59:27 +0000
commit9abe01a5881ae7fb43d2706ca9302aa68cc0221b (patch)
tree97b3fabfd917c5513b4adbce20b37af1a78dac87 /server
parent5bc31e8267230fc4abfef34dcaa77ce5eae447b3 (diff)
downloadvaadin-framework-9abe01a5881ae7fb43d2706ca9302aa68cc0221b.tar.gz
vaadin-framework-9abe01a5881ae7fb43d2706ca9302aa68cc0221b.zip
Introduce "shouldWriteDefaultValues" property to DesignContext.
Change-Id: I979448e5af032333a6a2f7b99b11ab16c41d7b18
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractColorPicker.java8
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponent.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractEmbedded.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractField.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractLayout.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractMedia.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractTextField.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/Button.java4
-rw-r--r--server/src/main/java/com/vaadin/ui/CheckBox.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/GridLayout.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/Link.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/MenuBar.java26
-rw-r--r--server/src/main/java/com/vaadin/ui/PasswordField.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/ProgressBar.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/Slider.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/TabSheet.java23
-rw-r--r--server/src/main/java/com/vaadin/ui/TextField.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/Video.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/Window.java5
-rw-r--r--server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java30
-rw-r--r--server/src/main/java/com/vaadin/ui/declarative/DesignContext.java29
21 files changed, 101 insertions, 72 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
index a537df0b21..b950361798 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
@@ -514,12 +514,14 @@ public abstract class AbstractColorPicker extends AbstractField<Color> {
Attributes attribute = design.attributes();
DesignAttributeHandler.writeAttribute("color", attribute,
- getValue().getCSS(), Color.WHITE.getCSS(), String.class);
+ getValue().getCSS(), Color.WHITE.getCSS(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("popup-style", attribute,
popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple",
- "normal", String.class);
+ "normal", String.class, designContext);
DesignAttributeHandler.writeAttribute("position", attribute,
- positionX + "," + positionY, "0,0", String.class);
+ positionX + "," + positionY, "0,0", String.class,
+ designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
index 0681612996..94fa738dd3 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
@@ -1240,7 +1240,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
Attributes attr = design.attributes();
// handle default attributes
for (String attribute : getDefaultAttributes()) {
- DesignAttributeHandler.writeAttribute(this, attribute, attr, def);
+ DesignAttributeHandler.writeAttribute(this, attribute, attr, def,
+ designContext);
}
// handle locale
if (getLocale() != null && (getParent() == null
@@ -1261,7 +1262,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
if (this instanceof Focusable) {
DesignAttributeHandler.writeAttribute("tabindex", attr,
((Focusable) this).getTabIndex(),
- ((Focusable) def).getTabIndex(), Integer.class);
+ ((Focusable) def).getTabIndex(), Integer.class,
+ designContext);
}
// handle custom attributes
Map<String, String> customAttributes = designContext
diff --git a/server/src/main/java/com/vaadin/ui/AbstractEmbedded.java b/server/src/main/java/com/vaadin/ui/AbstractEmbedded.java
index 978e82d468..a91332f948 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractEmbedded.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractEmbedded.java
@@ -100,7 +100,8 @@ public abstract class AbstractEmbedded extends AbstractComponent {
super.writeDesign(design, designContext);
AbstractEmbedded def = designContext.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("alt", design.attributes(),
- getAlternateText(), def.getAlternateText(), String.class);
+ getAlternateText(), def.getAlternateText(), String.class,
+ designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/AbstractField.java b/server/src/main/java/com/vaadin/ui/AbstractField.java
index c87a72e430..4add30183e 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractField.java
@@ -121,7 +121,8 @@ public abstract class AbstractField<T> extends AbstractComponent
AbstractField<T> def = designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("readonly", attr,
- super.isReadOnly(), def.isReadOnly(), Boolean.class);
+ super.isReadOnly(), def.isReadOnly(), Boolean.class,
+ designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/AbstractLayout.java b/server/src/main/java/com/vaadin/ui/AbstractLayout.java
index 3c31e59e2c..a4b4f06bf7 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractLayout.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractLayout.java
@@ -102,24 +102,25 @@ public abstract class AbstractLayout extends AbstractComponentContainer
MarginInfo defMargin, DesignContext context) {
if (margin.hasAll()) {
DesignAttributeHandler.writeAttribute("margin", design.attributes(),
- margin.hasAll(), defMargin.hasAll(), boolean.class);
+ margin.hasAll(), defMargin.hasAll(), boolean.class,
+ context);
} else {
DesignAttributeHandler.writeAttribute("margin-left",
design.attributes(), margin.hasLeft(), defMargin.hasLeft(),
- boolean.class);
+ boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-right",
design.attributes(), margin.hasRight(),
- defMargin.hasRight(), boolean.class);
+ defMargin.hasRight(), boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-top",
design.attributes(), margin.hasTop(), defMargin.hasTop(),
- boolean.class);
+ boolean.class, context);
DesignAttributeHandler.writeAttribute("margin-bottom",
design.attributes(), margin.hasBottom(),
- defMargin.hasBottom(), boolean.class);
+ defMargin.hasBottom(), boolean.class, context);
}
}
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractMedia.java b/server/src/main/java/com/vaadin/ui/AbstractMedia.java
index f56f6a7f27..a992554d67 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractMedia.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractMedia.java
@@ -275,7 +275,7 @@ public abstract class AbstractMedia extends AbstractComponent {
for (Resource r : getSources()) {
Attributes attr = design.appendElement("source").attributes();
DesignAttributeHandler.writeAttribute("href", attr, r, null,
- Resource.class);
+ Resource.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractTextField.java b/server/src/main/java/com/vaadin/ui/AbstractTextField.java
index ee2ccc6604..714f4b8e64 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractTextField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractTextField.java
@@ -285,7 +285,7 @@ public abstract class AbstractTextField extends AbstractField<String>
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(),
- def.getMaxLength(), Integer.class);
+ def.getMaxLength(), Integer.class, designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/Button.java b/server/src/main/java/com/vaadin/ui/Button.java
index 499713ffbd..86321f357c 100644
--- a/server/src/main/java/com/vaadin/ui/Button.java
+++ b/server/src/main/java/com/vaadin/ui/Button.java
@@ -637,11 +637,11 @@ public class Button extends AbstractFocusable
// icon-alt
DesignAttributeHandler.writeAttribute("icon-alt", attr,
getIconAlternateText(), def.getIconAlternateText(),
- String.class);
+ String.class, designContext);
// click-shortcut
if (clickShortcut != null) {
DesignAttributeHandler.writeAttribute("click-shortcut", attr,
- clickShortcut, null, ShortcutAction.class);
+ clickShortcut, null, ShortcutAction.class, designContext);
}
}
}
diff --git a/server/src/main/java/com/vaadin/ui/CheckBox.java b/server/src/main/java/com/vaadin/ui/CheckBox.java
index 02d7b0db8b..9a6394863e 100644
--- a/server/src/main/java/com/vaadin/ui/CheckBox.java
+++ b/server/src/main/java/com/vaadin/ui/CheckBox.java
@@ -218,7 +218,7 @@ public class CheckBox extends AbstractField<Boolean>
CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
- def.getValue(), Boolean.class);
+ def.getValue(), Boolean.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java
index 40b8575c36..08ca2cb2b3 100644
--- a/server/src/main/java/com/vaadin/ui/GridLayout.java
+++ b/server/src/main/java/com/vaadin/ui/GridLayout.java
@@ -27,7 +27,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.Set;
import org.jsoup.nodes.Attributes;
@@ -1453,7 +1452,7 @@ public class GridLayout extends AbstractLayout
// Row Expand
DesignAttributeHandler.writeAttribute("expand", row.attributes(),
- (int) getRowExpandRatio(i), 0, int.class);
+ (int) getRowExpandRatio(i), 0, int.class, designContext);
int colspan = 1;
Element col;
diff --git a/server/src/main/java/com/vaadin/ui/Link.java b/server/src/main/java/com/vaadin/ui/Link.java
index 24c1433968..b80e8cd206 100644
--- a/server/src/main/java/com/vaadin/ui/Link.java
+++ b/server/src/main/java/com/vaadin/ui/Link.java
@@ -226,9 +226,11 @@ public class Link extends AbstractComponent {
super.writeDesign(design, designContext);
Link def = designContext.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute("target", design.attributes(),
- getTargetName(), def.getTargetName(), String.class);
+ getTargetName(), def.getTargetName(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("href", design.attributes(),
- getResource(), def.getResource(), Resource.class);
+ getResource(), def.getResource(), Resource.class,
+ designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/MenuBar.java b/server/src/main/java/com/vaadin/ui/MenuBar.java
index 24f2dd89b3..884c3d4eb3 100644
--- a/server/src/main/java/com/vaadin/ui/MenuBar.java
+++ b/server/src/main/java/com/vaadin/ui/MenuBar.java
@@ -947,13 +947,14 @@ public class MenuBar extends AbstractComponent
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
for (MenuItem item : getItems()) {
- design.appendChild(createMenuElement(item));
+ design.appendChild(createMenuElement(item, designContext));
}
// in many cases there seems to be an empty more menu item
if (getMoreMenuItem() != null
&& !getMoreMenuItem().getText().isEmpty()) {
- Element moreMenu = createMenuElement(getMoreMenuItem());
+ Element moreMenu = createMenuElement(getMoreMenuItem(),
+ designContext);
moreMenu.attr("more", true);
design.appendChild(moreMenu);
}
@@ -963,34 +964,35 @@ public class MenuBar extends AbstractComponent
}
}
- protected Element createMenuElement(MenuItem item) {
+ protected Element createMenuElement(MenuItem item, DesignContext context) {
Element menuElement = new Element(Tag.valueOf("menu"), "");
// Defaults
MenuItem def = new MenuItem("", null, null);
Attributes attr = menuElement.attributes();
DesignAttributeHandler.writeAttribute("icon", attr, item.getIcon(),
- def.getIcon(), Resource.class);
+ def.getIcon(), Resource.class, context);
DesignAttributeHandler.writeAttribute("disabled", attr,
- !item.isEnabled(), !def.isEnabled(), boolean.class);
+ !item.isEnabled(), !def.isEnabled(), boolean.class, context);
DesignAttributeHandler.writeAttribute("visible", attr, item.isVisible(),
- def.isVisible(), boolean.class);
+ def.isVisible(), boolean.class, context);
DesignAttributeHandler.writeAttribute("separator", attr,
- item.isSeparator(), def.isSeparator(), boolean.class);
+ item.isSeparator(), def.isSeparator(), boolean.class, context);
DesignAttributeHandler.writeAttribute("checkable", attr,
- item.isCheckable(), def.isCheckable(), boolean.class);
+ item.isCheckable(), def.isCheckable(), boolean.class, context);
DesignAttributeHandler.writeAttribute("checked", attr, item.isChecked(),
- def.isChecked(), boolean.class);
+ def.isChecked(), boolean.class, context);
DesignAttributeHandler.writeAttribute("description", attr,
- item.getDescription(), def.getDescription(), String.class);
+ item.getDescription(), def.getDescription(), String.class,
+ context);
DesignAttributeHandler.writeAttribute("style-name", attr,
- item.getStyleName(), def.getStyleName(), String.class);
+ item.getStyleName(), def.getStyleName(), String.class, context);
menuElement.append(item.getText());
if (item.hasChildren()) {
for (MenuItem subMenu : item.getChildren()) {
- menuElement.appendChild(createMenuElement(subMenu));
+ menuElement.appendChild(createMenuElement(subMenu, context));
}
}
diff --git a/server/src/main/java/com/vaadin/ui/PasswordField.java b/server/src/main/java/com/vaadin/ui/PasswordField.java
index 231236c01f..7a154b2b29 100644
--- a/server/src/main/java/com/vaadin/ui/PasswordField.java
+++ b/server/src/main/java/com/vaadin/ui/PasswordField.java
@@ -76,6 +76,6 @@ public class PasswordField extends TextField {
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/ProgressBar.java b/server/src/main/java/com/vaadin/ui/ProgressBar.java
index 7df0fc5f83..e5d82a62b0 100644
--- a/server/src/main/java/com/vaadin/ui/ProgressBar.java
+++ b/server/src/main/java/com/vaadin/ui/ProgressBar.java
@@ -126,7 +126,7 @@ public class ProgressBar extends AbstractComponent {
Float defaultValue = ((ProgressBar) designContext
.getDefaultInstance(this)).getValue();
DesignAttributeHandler.writeAttribute("value", design.attributes(),
- getValue(), defaultValue, Float.class);
+ getValue(), defaultValue, Float.class, designContext);
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/Slider.java b/server/src/main/java/com/vaadin/ui/Slider.java
index 397e33e7c3..3a1d77e38f 100644
--- a/server/src/main/java/com/vaadin/ui/Slider.java
+++ b/server/src/main/java/com/vaadin/ui/Slider.java
@@ -372,7 +372,7 @@ public class Slider extends AbstractField<Double> {
}
Slider defaultSlider = context.getDefaultInstance(this);
DesignAttributeHandler.writeAttribute(this, "value",
- design.attributes(), defaultSlider);
+ design.attributes(), defaultSlider, context);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java
index 7a154dd752..b19acf8ddb 100644
--- a/server/src/main/java/com/vaadin/ui/TabSheet.java
+++ b/server/src/main/java/com/vaadin/ui/TabSheet.java
@@ -1556,29 +1556,32 @@ public class TabSheet extends AbstractComponentContainer
Attributes attr = tabElement.attributes();
// write attributes
DesignAttributeHandler.writeAttribute("visible", attr, tab.isVisible(),
- def.isVisible(), Boolean.class);
+ def.isVisible(), Boolean.class, designContext);
DesignAttributeHandler.writeAttribute("closable", attr,
- tab.isClosable(), def.isClosable(), Boolean.class);
+ tab.isClosable(), def.isClosable(), Boolean.class,
+ designContext);
DesignAttributeHandler.writeAttribute("caption", attr, tab.getCaption(),
- def.getCaption(), String.class);
+ def.getCaption(), String.class, designContext);
DesignAttributeHandler.writeAttribute("enabled", attr, tab.isEnabled(),
- def.isEnabled(), Boolean.class);
+ def.isEnabled(), Boolean.class, designContext);
DesignAttributeHandler.writeAttribute("icon", attr, tab.getIcon(),
- def.getIcon(), Resource.class);
+ def.getIcon(), Resource.class, designContext);
DesignAttributeHandler.writeAttribute("icon-alt", attr,
tab.getIconAlternateText(), def.getIconAlternateText(),
- String.class);
+ String.class, designContext);
DesignAttributeHandler.writeAttribute("description", attr,
- tab.getDescription(), def.getDescription(), String.class);
+ tab.getDescription(), def.getDescription(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("style-name", attr,
- tab.getStyleName(), def.getStyleName(), String.class);
+ tab.getStyleName(), def.getStyleName(), String.class,
+ designContext);
DesignAttributeHandler.writeAttribute("id", attr, tab.getId(),
- def.getId(), String.class);
+ def.getId(), String.class, designContext);
if (getSelectedTab() != null
&& getSelectedTab().equals(tab.getComponent())) {
// use write attribute to get consistent handling for boolean
DesignAttributeHandler.writeAttribute("selected", attr, true, false,
- boolean.class);
+ boolean.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/TextField.java b/server/src/main/java/com/vaadin/ui/TextField.java
index c01650fb60..b6eec11795 100644
--- a/server/src/main/java/com/vaadin/ui/TextField.java
+++ b/server/src/main/java/com/vaadin/ui/TextField.java
@@ -87,6 +87,6 @@ public class TextField extends AbstractTextField {
.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("value", attr, getValue(),
- def.getValue(), String.class);
+ def.getValue(), String.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/Video.java b/server/src/main/java/com/vaadin/ui/Video.java
index a9c3f3e729..af0ef618a4 100644
--- a/server/src/main/java/com/vaadin/ui/Video.java
+++ b/server/src/main/java/com/vaadin/ui/Video.java
@@ -118,7 +118,7 @@ public class Video extends AbstractMedia {
if (getPoster() != null) {
Attributes attr = design.appendElement("poster").attributes();
DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
- null, Resource.class);
+ null, Resource.class, designContext);
}
}
diff --git a/server/src/main/java/com/vaadin/ui/Window.java b/server/src/main/java/com/vaadin/ui/Window.java
index 82acf0ee6f..df06e54457 100644
--- a/server/src/main/java/com/vaadin/ui/Window.java
+++ b/server/src/main/java/com/vaadin/ui/Window.java
@@ -1406,7 +1406,7 @@ public class Window extends Panel
}
DesignAttributeHandler.writeAttribute("position", design.attributes(),
- getPosition(), def.getPosition(), String.class);
+ getPosition(), def.getPosition(), String.class, context);
// Process keyboard shortcuts
if (closeShortcuts.size() == 1 && hasCloseShortcut(KeyCode.ESCAPE)) {
@@ -1425,7 +1425,8 @@ public class Window extends Panel
// Write everything except the last "," to the design
DesignAttributeHandler.writeAttribute("close-shortcut",
- design.attributes(), attrString.trim(), null, String.class);
+ design.attributes(), attrString.trim(), null, String.class,
+ context);
}
for (Component c : getAssistiveDescription()) {
diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
index 4d655e0cbf..2eea59a046 100644
--- a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
@@ -56,25 +56,10 @@ public class DesignAttributeHandler implements Serializable {
return Logger.getLogger(DesignAttributeHandler.class.getName());
}
- private static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
+ private final static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
// translates string <-> object
- private static DesignFormatter FORMATTER = new DesignFormatter();
-
- private static boolean writeDefaultValues = false;
-
- /**
- * Set whether default attribute values should be written by the
- * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class)}
- * method. Default is {@code false}.
- *
- * @param value
- * {@code true} to write default values of attributes,
- * {@code false} to disable writing of default values
- */
- public static void setWriteDefaultValues(boolean value) {
- writeDefaultValues = value;
- }
+ private final static DesignFormatter FORMATTER = new DesignFormatter();
/**
* Returns the currently used formatter. All primitive types and all types
@@ -212,7 +197,7 @@ public class DesignAttributeHandler implements Serializable {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void writeAttribute(Object component, String attribute,
- Attributes attr, Object defaultInstance) {
+ Attributes attr, Object defaultInstance, DesignContext context) {
Method getter = findGetterForAttribute(component.getClass(), attribute);
if (getter == null) {
getLogger().warning(
@@ -223,7 +208,7 @@ public class DesignAttributeHandler implements Serializable {
Object value = getter.invoke(component);
Object defaultValue = getter.invoke(defaultInstance);
writeAttribute(attribute, attr, value, defaultValue,
- (Class) getter.getReturnType());
+ (Class) getter.getReturnType(), context);
} catch (Exception e) {
getLogger().log(Level.SEVERE,
"Failed to invoke getter for attribute " + attribute,
@@ -248,13 +233,14 @@ public class DesignAttributeHandler implements Serializable {
* the type of the input value
*/
public static <T> void writeAttribute(String attribute,
- Attributes attributes, T value, T defaultValue,
- Class<T> inputType) {
+ Attributes attributes, T value, T defaultValue, Class<T> inputType,
+ DesignContext context) {
if (!getFormatter().canConvert(inputType)) {
throw new IllegalArgumentException(
"input type: " + inputType.getName() + " not supported");
}
- if (writeDefaultValues || !SharedUtil.equals(value, defaultValue)) {
+ if (context.shouldWriteDefaultValues()
+ || !SharedUtil.equals(value, defaultValue)) {
String attributeValue = toAttributeValue(inputType, value);
if ("".equals(attributeValue) && (inputType == boolean.class
|| inputType == Boolean.class)) {
diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java b/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java
index ecbd5e638c..c8e794c46a 100644
--- a/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java
+++ b/server/src/main/java/com/vaadin/ui/declarative/DesignContext.java
@@ -94,6 +94,8 @@ public class DesignContext implements Serializable {
// this cannot be static because of testability issues
private Boolean legacyDesignPrefix = null;
+ private boolean shouldWriteDefaultValues = false;
+
public DesignContext(Document doc) {
this.doc = doc;
// Initialize the mapping between prefixes and package names.
@@ -831,4 +833,31 @@ public class DesignContext implements Serializable {
}
map.put(attribute, value);
}
+
+ /**
+ * Set whether default attribute values should be written by the
+ * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+ * method. Default is {@code false}.
+ *
+ * @since 8.0
+ * @param value
+ * {@code true} to write default values of attributes,
+ * {@code false} to disable writing of default values
+ */
+ public void setShouldWriteDefaultValues(boolean value) {
+ shouldWriteDefaultValues = value;
+ }
+
+ /**
+ * Determines whether default attribute values should be written by the
+ * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+ * method. Default is {@code false}.
+ *
+ * @since 8.0
+ * @return {@code true} if default values of attributes should be written,
+ * otherwise {@code false}
+ */
+ public boolean shouldWriteDefaultValues() {
+ return shouldWriteDefaultValues;
+ }
}