From 5e27f326fdb4470d4ffe601e1cd4c9a7eae501d7 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Wed, 9 Jan 2013 16:17:37 +0200 Subject: [PATCH] Merge of (#8004) to Vaadin 7. Empty RichTextArea returns "
" as getValue(). Change-Id: I5190d55b0e1d32ed4dd181434006820db9220ada --- .../com/vaadin/client/ui/VRichTextArea.java | 33 ++++++++++++++- .../richtextarea/RichTextAreaEmptyString.java | 42 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/richtextarea/RichTextAreaEmptyString.java diff --git a/client/src/com/vaadin/client/ui/VRichTextArea.java b/client/src/com/vaadin/client/ui/VRichTextArea.java index 7cb7f9ec59..1498c096ed 100644 --- a/client/src/com/vaadin/client/ui/VRichTextArea.java +++ b/client/src/com/vaadin/client/ui/VRichTextArea.java @@ -191,7 +191,7 @@ public class VRichTextArea extends Composite implements Field, ChangeHandler, */ public void synchronizeContentToServer() { if (client != null && id != null) { - final String html = rta.getHTML(); + final String html = sanitizeRichTextAreaValue(rta.getHTML()); if (!html.equals(currentValue)) { client.updateVariable(id, "text", html, immediate); currentValue = html; @@ -199,6 +199,37 @@ public class VRichTextArea extends Composite implements Field, ChangeHandler, } } + /** + * Browsers differ in what they return as the content of a visually empty + * rich text area. This method is used to normalize these to an empty + * string. See #8004. + * + * @param html + * @return cleaned html string + */ + private String sanitizeRichTextAreaValue(String html) { + BrowserInfo browser = BrowserInfo.get(); + String result = html; + if (browser.isFirefox()) { + if ("
".equals(html)) { + result = ""; + } + } else if (browser.isWebkit()) { + if ("

".equals(html)) { + result = ""; + } + } else if (browser.isIE()) { + if ("

 

".equals(html)) { + result = ""; + } + } else if (browser.isOpera()) { + if ("
".equals(html) || "


".equals(html)) { + result = ""; + } + } + return result; + } + @Override public void onBlur(BlurEvent event) { synchronizeContentToServer(); diff --git a/uitest/src/com/vaadin/tests/components/richtextarea/RichTextAreaEmptyString.java b/uitest/src/com/vaadin/tests/components/richtextarea/RichTextAreaEmptyString.java new file mode 100644 index 0000000000..5eddf9dc6d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/richtextarea/RichTextAreaEmptyString.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.components.richtextarea; + +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; +import com.vaadin.ui.RichTextArea; + +public class RichTextAreaEmptyString extends TestBase { + + @Override + protected String getDescription() { + return "Test the value of a rich text area. Visually empty area should return \"\""; + } + + @Override + protected Integer getTicketNumber() { + return 8004; + } + + @Override + protected void setup() { + final RichTextArea area = new RichTextArea(); + + final Label l = new Label(area.getValue(), ContentMode.PREFORMATTED); + l.setCaption("Value recieved from RichTextArea:"); + + final Button b = new Button("get area value", new ClickListener() { + + public void buttonClick(ClickEvent event) { + l.setValue(area.getValue()); + } + }); + + addComponent(area); + addComponent(b); + addComponent(l); + } + +} -- 2.39.5