summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Murtojarvi <mika@vaadin.com>2014-12-09 13:34:33 +0200
committerMika Murtojarvi <mika@vaadin.com>2014-12-09 15:59:48 +0200
commit12e5d620ab2ce885590a280d2c19e230cc083bb6 (patch)
tree2dcfa896ed22383952fe07aee821aeb72aa06a5e
parent18b333ee3dfd171956829e97a32baa8069346c65 (diff)
downloadvaadin-framework-12e5d620ab2ce885590a280d2c19e230cc083bb6.tar.gz
vaadin-framework-12e5d620ab2ce885590a280d2c19e230cc083bb6.zip
Handle immediate property as a special case (#7749).
Change-Id: I507b44acfd3036d2d2862d1d04b518adc7bf826a
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java15
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java31
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java4
3 files changed, 49 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 8349dcfa25..11e24a306e 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -930,6 +930,14 @@ public abstract class AbstractComponent extends AbstractClientConnector
for (String attribute : getDefaultAttributes()) {
DesignAttributeHandler.readAttribute(this, attribute, attr, def);
}
+ // handle immediate
+ if (attr.hasKey("immediate")) {
+ String str = attr.get("immediate");
+ boolean immediate = "".equals(str) ? true : Boolean.valueOf(str);
+ setImmediate(immediate);
+ } else {
+ explicitImmediateValue = null;
+ }
// handle width and height
readSize(attr, def);
// handle component error
@@ -1162,7 +1170,8 @@ 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" };
+ "width-full", "height-full", "size-auto", "size-full",
+ "responsive", "immediate" };
/*
* (non-Javadoc)
@@ -1182,6 +1191,10 @@ public abstract class AbstractComponent extends AbstractClientConnector
for (String attribute : getDefaultAttributes()) {
DesignAttributeHandler.writeAttribute(this, attribute, attr, def);
}
+ // handle immediate
+ if (explicitImmediateValue != null) {
+ design.attr("immediate", explicitImmediateValue.toString());
+ }
// handle size
writeSize(attr, def);
// handle component error
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java
index d32155fd68..06fc59a2f3 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeFromDesign.java
@@ -15,6 +15,8 @@
*/
package com.vaadin.tests.server.component.abstractcomponent;
+import java.lang.reflect.Field;
+
import junit.framework.TestCase;
import org.jsoup.nodes.Attributes;
@@ -102,6 +104,23 @@ public class TestSynchronizeFromDesign extends TestCase {
AbstractComponent component = getComponent();
component.synchronizeFromDesign(design, ctx);
assertEquals(true, component.isImmediate());
+ assertEquals(Boolean.TRUE, getExplicitImmediate(component));
+ // Synchronize with a design having no immediate attribute -
+ // explicitImmediate should then be null.
+ design = createDesign("description", "test-description");
+ component.synchronizeFromDesign(design, ctx);
+ assertEquals(null, getExplicitImmediate(component));
+ // Synchronize with a design having immediate = false
+ design = createDesign("immediate", "false");
+ component.synchronizeFromDesign(design, ctx);
+ assertEquals(false, component.isImmediate());
+ assertEquals(Boolean.FALSE, getExplicitImmediate(component));
+ // Synchronize with a design having immediate = "" - should correspond to
+ // true.
+ design = createDesign("immediate", "");
+ component.synchronizeFromDesign(design, ctx);
+ assertEquals(true, component.isImmediate());
+ assertEquals(Boolean.TRUE, getExplicitImmediate(component));
}
public void testSynchronizeDescription() {
@@ -219,4 +238,16 @@ public class TestSynchronizeFromDesign extends TestCase {
Element node = new Element(Tag.valueOf("v-label"), "", attributes);
return node;
}
+
+ private Boolean getExplicitImmediate(AbstractComponent component) {
+ try {
+ Field immediate = AbstractComponent.class
+ .getDeclaredField("explicitImmediateValue");
+ immediate.setAccessible(true);
+ return (Boolean) immediate.get(component);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Getting the field explicitImmediateValue failed.");
+ }
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java
index f0eb05f364..5b65dce8ac 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestSynchronizeToDesign.java
@@ -126,6 +126,10 @@ public class TestSynchronizeToDesign extends TestCase {
public void testSynchronizeImmediate() {
Element design = createDesign();
AbstractComponent component = getComponent();
+ // no immediate attribute should be written before setting immediate to
+ // some value
+ component.synchronizeFromDesign(design, ctx);
+ assertFalse(design.hasAttr("immediate"));
component.setImmediate(true);
component.synchronizeToDesign(design, ctx);
// we only changed one of the attributes, others are at default values