From 6291a5080e2a6d2f0c5a955e5cf9ae984763a5aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Risto=20Yrj=C3=A4n=C3=A4?= Date: Fri, 28 Jun 2013 15:53:03 +0300 Subject: [PATCH] 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 --- server/src/com/vaadin/ui/Slider.java | 17 +++++ .../slider/SliderUpdateFromValueChange.html | 37 +++++++++++ .../slider/SliderUpdateFromValueChange.java | 65 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.html create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderUpdateFromValueChange.java 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 { @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 @@ + + + + + + +SliderUpdateFromValueChange + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SliderUpdateFromValueChange
open/run/com.vaadin.tests.components.slider.SliderUpdateFromValueChange?restartApplication
dragAndDropvaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]67,0
dragAndDropvaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]-188,0
assertNotAttributevaadin=runcomvaadintestscomponentssliderSliderUpdateFromValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]@styleregex:.*(margin-left|MARGIN-LEFT): 0px.*
+ + 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; + } +} -- 2.39.5