*/
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;
}
}
+ /**
+ * 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 ("<br>".equals(html)) {
+ result = "";
+ }
+ } else if (browser.isWebkit()) {
+ if ("<div><br></div>".equals(html)) {
+ result = "";
+ }
+ } else if (browser.isIE()) {
+ if ("<P> </P>".equals(html)) {
+ result = "";
+ }
+ } else if (browser.isOpera()) {
+ if ("<br>".equals(html) || "<p><br></p>".equals(html)) {
+ result = "";
+ }
+ }
+ return result;
+ }
+
@Override
public void onBlur(BlurEvent event) {
synchronizeContentToServer();
--- /dev/null
+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);
+ }
+
+}