]> source.dussan.org Git - vaadin-framework.git/commitdiff
Do not send value change to server for non-immediate CheckBox (#18102)
authorTeppo Kurki <teppo.kurki@vaadin.com>
Wed, 3 Jun 2015 19:06:42 +0000 (22:06 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 4 Jun 2015 11:34:57 +0000 (11:34 +0000)
Change-Id: I60a58af72d7166869d8bdc8930e16440e02d2ac5

client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
shared/src/com/vaadin/shared/ui/checkbox/CheckBoxServerRpc.java
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java

index 63984ff2256ebf22c53f85d85cf414c253280b88..9e689f3314e6a0f13d41666bdf936e72c12db6ee 100644 (file)
@@ -158,6 +158,9 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
                             .getElement());
             getRpcProxy(CheckBoxServerRpc.class).setChecked(getState().checked,
                     details);
+            if (getState().immediate) {
+                getConnection().sendPendingVariableChanges();
+            }
         }
     }
 }
index 0041da4dfa7084dc77fff1308774cf7ff8ed544e..f4124100e0dd167275034ceacded2602bc6449f2 100644 (file)
 package com.vaadin.shared.ui.checkbox;
 
 import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.annotations.Delayed;
 import com.vaadin.shared.communication.ServerRpc;
 
 public interface CheckBoxServerRpc extends ServerRpc {
+    @Delayed
     public void setChecked(boolean checked, MouseEventDetails mouseEventDetails);
 }
diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java
new file mode 100644 (file)
index 0000000..fec753d
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.checkbox;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Label;
+
+public class CheckBoxImmediate extends AbstractTestUI {
+    private int count = 0;
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final Label status = new Label("Events received: " + count);
+        status.setId("count");
+        addComponent(status);
+
+        CheckBox cb = new CheckBox("Non-immediate");
+        ValueChangeListener listener = new ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                count++;
+                status.setValue("Events received: " + count);
+            }
+        };
+        cb.addValueChangeListener(listener);
+        cb.setImmediate(false);
+        addComponent(cb);
+
+        cb = new CheckBox("Immediate");
+        cb.addValueChangeListener(listener);
+        cb.setImmediate(true);
+        addComponent(cb);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Test for verifying that a non-immediate CheckBox does not send value change to server immediately.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 18102;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java
new file mode 100644 (file)
index 0000000..826b43b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.checkbox;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.CheckBoxElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class CheckBoxImmediateTest extends MultiBrowserTest {
+
+    @Test
+    public void testNonImmediateCheckBox() {
+        openTestURL();
+
+        CheckBoxElement checkBoxElement = $(CheckBoxElement.class).first();
+        WebElement inputElem = checkBoxElement.findElement(By.tagName("input"));
+        final WebElement countElem = $(LabelElement.class).id("count");
+
+        inputElem.click();
+        assertEquals("Events received: 0", countElem.getText());
+    }
+
+    @Test
+    public void testImmediateCheckBox() {
+        openTestURL();
+
+        CheckBoxElement checkBoxElement = $(CheckBoxElement.class).get(1);
+        WebElement inputElem = checkBoxElement.findElement(By.tagName("input"));
+        final WebElement countElem = $(LabelElement.class).id("count");
+
+        inputElem.click();
+        assertEquals("Events received: 1", countElem.getText());
+    }
+}
index bd44e8a074be734c03a3945f4c95aa9f2a6c84d0..f909f97996ca54cca9130a9e4571bf766adcde96 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.vaadin.tests.components.checkbox;
 
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
@@ -46,6 +48,14 @@ public class CheckBoxRpcCount extends AbstractTestUI {
                 });
             }
         };
+        cb.addValueChangeListener(new ValueChangeListener() {
+
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                // Adding an empty ValueChangeListener just to ensure that
+                // immediate mode is set to true
+            }
+        });
         addComponent(cb);
     }