aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRisto Yrjänä <risto.yrjana@vaadin.com>2013-06-28 15:53:03 +0300
committerVaadin Code Review <review@vaadin.com>2013-06-28 13:14:07 +0000
commit6291a5080e2a6d2f0c5a955e5cf9ae984763a5aa (patch)
treeda07964ae9ede1841ca4097a2d3127ca666f777d
parentda480bdce215249344a9c80bb257a4575f072ceb (diff)
downloadvaadin-framework-6291a5080e2a6d2f0c5a955e5cf9ae984763a5aa.tar.gz
vaadin-framework-6291a5080e2a6d2f0c5a955e5cf9ae984763a5aa.zip
Ensure that Slider diffstate always contains "value" (#12133)
Force diff state to contain "value", so that value changes from value change listeners work. Change-Id: I5b2c661f1297ec0272c150a5a9ff4ca26f19fefe
-rw-r--r--server/src/com/vaadin/ui/Slider.java17
-rw-r--r--uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.html37
-rw-r--r--uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.java65
3 files changed, 119 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index e63fdc5e10..44fc49ba9b 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -16,6 +16,8 @@
package com.vaadin.ui;
+import org.json.JSONException;
+
import com.vaadin.shared.ui.slider.SliderOrientation;
import com.vaadin.shared.ui.slider.SliderServerRpc;
import com.vaadin.shared.ui.slider.SliderState;
@@ -32,6 +34,21 @@ public class Slider extends AbstractField<Double> {
@Override
public void valueChanged(double value) {
+ /*
+ * Client side updates the state before sending the event so we need
+ * to make sure the cached state is updated to match the client. If
+ * we do not do this, a reverting setValue() call in a listener will
+ * not cause the new state to be sent to the client.
+ *
+ * See #12133.
+ */
+ try {
+ getUI().getConnectorTracker().getDiffState(Slider.this)
+ .put("value", value);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+
try {
setValue(value, true);
} catch (final ValueOutOfBoundsException e) {
diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.html b/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.html
new file mode 100644
index 0000000000..81c5938eb2
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.html
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>SliderUpdateFromValueChange</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">SliderUpdateFromValueChange</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.slider.SliderUpdateFromValueChange?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>dragAndDrop</td>
+ <td>vaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]</td>
+ <td>67,0</td>
+</tr>
+<tr>
+ <td>dragAndDrop</td>
+ <td>vaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]</td>
+ <td>-188,0</td>
+</tr>
+<tr>
+ <td>assertNotAttribute</td>
+ <td>vaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]@style</td>
+ <td>regex:.*(margin-left|MARGIN-LEFT): 0px.*</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.java b/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.java
new file mode 100644
index 0000000000..21b56b7972
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2000-2013 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.slider;
+
+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.Slider;
+
+/**
+ * Testcase for #12133
+ *
+ * @author Vaadin Ltd
+ */
+public class SliderUpdateFromValueChange extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Slider slider = new Slider(0, 100, 1);
+ slider.addValueChangeListener(new ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Double value = (Double) event.getProperty().getValue();
+ if (value < 100.0) {
+ slider.setValue(100.0);
+ }
+ slider.markAsDirty();
+ }
+
+ });
+ slider.setImmediate(true);
+ slider.setWidth(200, Unit.PIXELS);
+
+ addComponent(slider);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Slider.setValue() does not update graphical representation of Slider component";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 12133;
+ }
+}