From 5e27f326fdb4470d4ffe601e1cd4c9a7eae501d7 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Wed, 9 Jan 2013 16:17:37 +0200 Subject: Merge of (#8004) to Vaadin 7. Empty RichTextArea returns "
" as getValue(). Change-Id: I5190d55b0e1d32ed4dd181434006820db9220ada --- client/src/com/vaadin/client/ui/VRichTextArea.java | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'client') 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(); -- cgit v1.2.3