summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Label.java31
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java33
2 files changed, 58 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java
index 2b96d51fa5..1498246ec5 100644
--- a/server/src/com/vaadin/ui/Label.java
+++ b/server/src/com/vaadin/ui/Label.java
@@ -625,12 +625,31 @@ public class Label extends AbstractComponent implements Property<String>,
super.writeDesign(design, designContext);
String content = getValue();
if (content != null) {
- design.html(getValue());
- }
- // plain-text (default is html)
- if (getContentMode() == ContentMode.TEXT) {
- design.attr(DESIGN_ATTR_PLAIN_TEXT, true);
- design.html(DesignFormatter.encodeForTextNode(getValue()));
+ switch (getContentMode()) {
+ case TEXT:
+ case PREFORMATTED:
+ case XML:
+ case RAW: {
+ // FIXME This attribute is not enough to be able to restore the
+ // content mode in readDesign. The content mode should instead
+ // be written directly in the attribute and restored in
+ // readDesign. See ticket #19435
+ design.attr(DESIGN_ATTR_PLAIN_TEXT, true);
+ String encodeForTextNode = DesignFormatter
+ .encodeForTextNode(content);
+ if (encodeForTextNode != null) {
+ design.html(encodeForTextNode);
+ }
+ }
+ break;
+ case HTML:
+ design.html(content);
+ break;
+ default:
+ throw new IllegalStateException(
+ "ContentMode " + getContentMode()
+ + " is not supported by writeDesign");
+ }
}
}
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
index f911aab779..7a7f4bd844 100644
--- a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
@@ -18,6 +18,7 @@ package com.vaadin.tests.server.component.label;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Tag;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
@@ -112,6 +113,38 @@ public class LabelDeclarativeTest extends DeclarativeTestBase<Label> {
Assert.assertEquals("&amp; Test", root.html());
}
+ @Test
+ public void testNullValue() {
+ Label label = new Label();
+ label.setValue(null);
+
+ label.setContentMode(ContentMode.TEXT);
+ Element root = new Element(Tag.valueOf("vaadin-label"), "");
+ label.writeDesign(root, new DesignContext());
+ Assert.assertEquals("", root.html());
+
+ label.setContentMode(ContentMode.HTML);
+ root = new Element(Tag.valueOf("vaadin-label"), "");
+ label.writeDesign(root, new DesignContext());
+ Assert.assertEquals("", root.html());
+ }
+
+ /**
+ * FIXME Using another content mode than TEXT OR HTML is currently not
+ * supported and will cause the content mode to fallback without the users
+ * knowledge to HTML. This test can be enabled when
+ * https://dev.vaadin.com/ticket/19435 is fixed.
+ */
+ @Test
+ @Ignore("Test ignored due to https://dev.vaadin.com/ticket/19435")
+ public void testContentModes() {
+ String design = "<vaadin-label caption='This\n is a label' />";
+ Label l = createLabel(null, "This\n is a label", true);
+ l.setContentMode(ContentMode.PREFORMATTED);
+ testRead(design, l);
+ testWrite(design, l);
+ }
+
private Label createLabel(String content, String caption, boolean html) {
Label label = new Label();
label.setContentMode(html ? ContentMode.HTML : ContentMode.TEXT);