]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Parse readonly values for AbstractFields correctly #18850"
authorMarkus Koivisto <markus@vaadin.com>
Wed, 30 Sep 2015 13:22:11 +0000 (16:22 +0300)
committerMarkus Koivisto <markus@vaadin.com>
Wed, 30 Sep 2015 13:22:11 +0000 (16:22 +0300)
This reverts commit 5e9209421ce92e16531299c8c4be5fdd412bb513.

20 files changed:
server/src/com/vaadin/ui/AbstractField.java
server/src/com/vaadin/ui/AbstractSelect.java
server/src/com/vaadin/ui/CheckBox.java
server/src/com/vaadin/ui/DateField.java
server/src/com/vaadin/ui/PasswordField.java
server/src/com/vaadin/ui/ProgressBar.java
server/src/com/vaadin/ui/RichTextArea.java
server/src/com/vaadin/ui/Slider.java
server/src/com/vaadin/ui/TextArea.java
server/src/com/vaadin/ui/TextField.java
server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java [deleted file]
server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/richtextarea/RichTextAreaDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java

index 61f58157ea018d6e6395851ddf4f59f4e38a3565..cf14d1cb96ca8bc5881de69d125c91433e8a0ac4 100644 (file)
@@ -264,9 +264,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
                     committingValueToDataSource = false;
                 }
             } else {
-                /*
-                 * An invalid value and we don't allow them, throw the exception
-                 */
+                /* An invalid value and we don't allow them, throw the exception */
                 validate();
             }
         }
@@ -461,35 +459,15 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * @param repaintIsNotNeeded
      *            True iff caller is sure that repaint is not needed.
      * @throws Property.ReadOnlyException
-     * @throws Converter.ConversionException
-     * @throws InvalidValueException
-     */
-    protected void setValue(T newFieldValue, boolean repaintIsNotNeeded) {
-        setValue(newFieldValue, repaintIsNotNeeded, false);
-    }
-
-    /**
-     * Sets the value of the field.
-     * 
-     * @since
-     * @param newFieldValue
-     *            the New value of the field.
-     * @param repaintIsNotNeeded
-     *            True iff caller is sure that repaint is not needed.
-     * @param ignoreReadOnly
-     *            True iff if the read-only check should be ignored
-     * @throws Property.ReadOnlyException
-     * @throws Converter.ConversionException
-     * @throws InvalidValueException
      */
-    protected void setValue(T newFieldValue, boolean repaintIsNotNeeded,
-            boolean ignoreReadOnly) throws Property.ReadOnlyException,
-            Converter.ConversionException, InvalidValueException {
+    protected void setValue(T newFieldValue, boolean repaintIsNotNeeded)
+            throws Property.ReadOnlyException, Converter.ConversionException,
+            InvalidValueException {
 
         if (!SharedUtil.equals(newFieldValue, getInternalValue())) {
 
             // Read only fields can not be changed
-            if (!ignoreReadOnly && isReadOnly()) {
+            if (isReadOnly()) {
                 throw new Property.ReadOnlyException();
             }
             try {
index 3a427562d265642dd1ef75bac3d313190494028c..bbd486a8f923f5d01fc329f4153826fe3126f0b1 100644 (file)
@@ -34,10 +34,8 @@ import org.jsoup.nodes.Element;
 import com.vaadin.data.Container;
 import com.vaadin.data.Item;
 import com.vaadin.data.Property;
-import com.vaadin.data.Validator.InvalidValueException;
 import com.vaadin.data.util.IndexedContainer;
 import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.Converter.ConversionException;
 import com.vaadin.data.util.converter.ConverterUtil;
 import com.vaadin.event.DataBoundTransferable;
 import com.vaadin.event.Transferable;
@@ -703,28 +701,22 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
      *            the New selected item or collection of selected items.
      * @param repaintIsNotNeeded
      *            True if caller is sure that repaint is not needed.
-     * @param ignoreReadOnly
-     *            True if read-only check should be omitted.
      * @see com.vaadin.ui.AbstractField#setValue(java.lang.Object,
      *      java.lang.Boolean)
      */
     @Override
-    protected void setValue(Object newFieldValue, boolean repaintIsNotNeeded,
-            boolean ignoreReadOnly)
-            throws com.vaadin.data.Property.ReadOnlyException,
-            ConversionException, InvalidValueException {
+    protected void setValue(Object newValue, boolean repaintIsNotNeeded)
+            throws Property.ReadOnlyException {
+
         if (isMultiSelect()) {
-            if (newFieldValue == null) {
-                super.setValue(new LinkedHashSet<Object>(), repaintIsNotNeeded,
-                        ignoreReadOnly);
-            } else if (Collection.class.isAssignableFrom(newFieldValue
-                    .getClass())) {
+            if (newValue == null) {
+                super.setValue(new LinkedHashSet<Object>(), repaintIsNotNeeded);
+            } else if (Collection.class.isAssignableFrom(newValue.getClass())) {
                 super.setValue(new LinkedHashSet<Object>(
-                        (Collection<?>) newFieldValue), repaintIsNotNeeded,
-                        ignoreReadOnly);
+                        (Collection<?>) newValue), repaintIsNotNeeded);
             }
-        } else if (newFieldValue == null || items.containsId(newFieldValue)) {
-            super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
+        } else if (newValue == null || items.containsId(newValue)) {
+            super.setValue(newValue, repaintIsNotNeeded);
         }
     }
 
@@ -2204,9 +2196,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
         }
         if (!selected.isEmpty()) {
             if (isMultiSelect()) {
-                setValue(selected, false, true);
+                setValue(selected);
             } else if (selected.size() == 1) {
-                setValue(selected.iterator().next(), false, true);
+                setValue(selected.iterator().next());
             } else {
                 throw new DesignException(
                         "Multiple values selected for a single select component");
index 8b31edcbb4cf405c23a73a52bbc6d1e901db56a2..e98a2b61b9bb53094704cacd05fcb6600d1b0952 100644 (file)
@@ -221,9 +221,8 @@ public class CheckBox extends AbstractField<Boolean> {
     public void readDesign(Element design, DesignContext designContext) {
         super.readDesign(design, designContext);
         if (design.hasAttr("checked")) {
-            this.setValue(
-                    DesignAttributeHandler.readAttribute("checked",
-                            design.attributes(), Boolean.class), false, true);
+            this.setValue(DesignAttributeHandler.readAttribute("checked",
+                    design.attributes(), Boolean.class));
         }
     }
 
index 052539cd2839b097143e9ad0233be2af24ba8f10..422b1ffdd8841fe4637ae4549f935567bc8d0891 100644 (file)
@@ -1078,7 +1078,7 @@ public class DateField extends AbstractField<Date> implements
                 Logger.getLogger(DateField.class.getName()).info(
                         "cannot parse " + design.attr("value") + " as date");
             }
-            this.setValue(date, false, true);
+            this.setValue(date);
         }
     }
 
index 385649c3186be7ec170467add9ffe3730fda3354..ff3b1fea1f805f7bf224618b7e0cacc499ba0c32 100644 (file)
@@ -94,7 +94,7 @@ public class PasswordField extends AbstractTextField {
         Attributes attr = design.attributes();
         if (attr.hasKey("value")) {
             setValue(DesignAttributeHandler.readAttribute("value", attr,
-                    String.class), false, true);
+                    String.class));
         }
     }
 
index d38067d51e378dec01d45a6f8f48c617d5440bcf..89baac1e64f8cf47b502badfd5436524fe286c72 100644 (file)
@@ -159,9 +159,8 @@ public class ProgressBar extends AbstractField<Float> implements
     public void readDesign(Element design, DesignContext designContext) {
         super.readDesign(design, designContext);
         if (design.hasAttr("value") && !design.attr("value").isEmpty()) {
-            setValue(
-                    DesignAttributeHandler.readAttribute("value",
-                            design.attributes(), Float.class), false, true);
+            setValue(DesignAttributeHandler.readAttribute("value",
+                    design.attributes(), Float.class));
         }
     }
 
index eff669c4c61d660685140a69bdfded74803d0bd5..7c23cce5cbdcb07f18516cb9e84ae75553eaece5 100644 (file)
@@ -300,7 +300,7 @@ public class RichTextArea extends AbstractField<String> implements
     @Override
     public void readDesign(Element design, DesignContext designContext) {
         super.readDesign(design, designContext);
-        setValue(design.html(), false, true);
+        setValue(design.html());
     }
 
     @Override
index 6b0880efd55204b18b9ac67fc5d2f0953f9b5abb..15c94b6d3cdb0d53c5e72a5499dc9eff6b5178f5 100644 (file)
@@ -370,10 +370,9 @@ public class Slider extends AbstractField<Double> {
         if (attr.hasKey("vertical")) {
             setOrientation(SliderOrientation.VERTICAL);
         }
-        if (attr.hasKey("value")) {
-            Double newFieldValue = DesignAttributeHandler.readAttribute(
-                    "value", attr, Double.class);
-            setValue(newFieldValue, false, true);
+        if (!attr.get("value").isEmpty()) {
+            setValue(DesignAttributeHandler.readAttribute("value", attr,
+                    Double.class));
         }
     }
 
index c2af125338714b67f0380d4f74f10a63a0caaedc..75ecc19d40926b3504aedf76f29be30f3ef2635e 100644 (file)
@@ -146,8 +146,7 @@ public class TextArea extends AbstractTextField {
     @Override
     public void readDesign(Element design, DesignContext designContext) {
         super.readDesign(design, designContext);
-        setValue(DesignFormatter.unencodeFromTextNode(design.html()), false,
-                true);
+        setValue(DesignFormatter.unencodeFromTextNode(design.html()));
     }
 
     /*
index 8772f95f3d8b36798e0667570e14445d88a048b2..2a61e9321121e2263be3907d6d484ab0cd3dc673 100644 (file)
@@ -115,9 +115,8 @@ public class TextField extends AbstractTextField {
         super.readDesign(design, designContext);
         Attributes attr = design.attributes();
         if (attr.hasKey("value")) {
-            String newFieldValue = DesignAttributeHandler.readAttribute(
-                    "value", attr, String.class);
-            setValue(newFieldValue, false, true);
+            setValue(DesignAttributeHandler.readAttribute("value", attr,
+                    String.class));
         }
     }
 
index 3ac81b2a84977aa904d464ed6dfe188343d09237..6162e41494b09389676c89525663edb97460089c 100644 (file)
@@ -44,14 +44,4 @@ public class CheckboxDeclarativeTest extends DeclarativeTestBase<CheckBox> {
         testRead(design, checkBox);
         testWrite(design, checkBox);
     }
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-check-box readonly checked='' />";
-        CheckBox checkBox = new CheckBox();
-        checkBox.setValue(true);
-        checkBox.setReadOnly(true);
-        testRead(design, checkBox);
-        testWrite(design, checkBox);
-    }
 }
index d49d2b79e235cadb41aed02d1a1f0879a9923cf2..e9d66b478b6ccf571b82a835a43fb44a4e636ae2 100644 (file)
@@ -57,22 +57,6 @@ public class ComboBoxDeclarativeTest extends DeclarativeTestBase<ComboBox> {
         testWrite(getBasicDesign(), getBasicExpected());
     }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-combo-box readonly value='foo'><option selected>foo</option></v-combo-box>";
-
-        ComboBox comboBox = new ComboBox();
-        comboBox.addItems("foo", "bar");
-        comboBox.setValue("foo");
-        comboBox.setReadOnly(true);
-
-        testRead(design, comboBox);
-
-        // Selects items are not written out by default
-        String design2 = "<v-combo-box readonly></v-combo-box>";
-        testWrite(design2, comboBox);
-    }
-
     private String getBasicDesign() {
         return "<v-combo-box input-prompt=\"Select something\" filtering-mode=\"off\" scroll-to-selected-item='false'>";
     }
index c3fc4bf723383d23ce038c423f345a3cde73b9db..5058cf5a5ffe39d83f4ef4bf4a99096cad9f5f0c 100644 (file)
@@ -87,16 +87,4 @@ public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> {
                         "2020-01-01 00:00:00+0200"),
                 getYearResolutionExpected());
     }
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-date-field readonly resolution='year' value='2020-01-01 00:00:00+0200'/>";
-        DateField df = new DateField();
-        df.setResolution(Resolution.YEAR);
-        df.setValue(new Date(2020 - 1900, 1 - 1, 1));
-        df.setReadOnly(true);
-
-        testRead(design, df);
-        testWrite(design, df);
-    }
 }
index 140335e1363d6f94bfe9e8db8b41fc8d8c995ad7..8f1b995cc62ee12b09e7104d112ecf09a6bd3621 100644 (file)
@@ -50,20 +50,4 @@ public class NativeSelectDeclarativeTest extends
         testWrite(stripOptionTags(getBasicDesign()), getBasicExpected());
     }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-native-select readonly><option selected>foo</option><option>bar</option></v-native-select>";
-
-        NativeSelect ns = new NativeSelect();
-        ns.addItems("foo", "bar");
-        ns.setValue("foo");
-        ns.setReadOnly(true);
-
-        testRead(design, ns);
-
-        // Selects items are not written out by default
-        String design2 = "<v-native-select readonly></v-native-select>";
-        testWrite(design2, ns);
-    }
-
 }
\ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java
deleted file mode 100644 (file)
index 6934d20..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.server.component.passwordfield;
-
-import org.junit.Test;
-
-import com.vaadin.tests.design.DeclarativeTestBase;
-import com.vaadin.ui.PasswordField;
-
-/**
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class PasswordFieldDeclarativeTest extends
-        DeclarativeTestBase<PasswordField> {
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-password-field readonly=\"\" value=\"test value\"/>";
-        PasswordField tf = new PasswordField();
-        tf.setValue("test value");
-        tf.setReadOnly(true);
-        testRead(design, tf);
-        testWrite(design, tf);
-    }
-}
index 6e42d0c1dd58ce8191595e42c06b8ab9d916c291..c98883a4a7e743e05545018183fb34d4eedc2701 100644 (file)
@@ -60,16 +60,4 @@ public class ProgressBarDeclarativeTest extends
         testWrite("<v-progress-bar>", new ProgressBar());
     }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-progress-bar readonly value=0.5 indeterminate=''>";
-        ProgressBar progressBar = new ProgressBar();
-        progressBar.setIndeterminate(true);
-        progressBar.setValue(0.5f);
-        progressBar.setReadOnly(true);
-
-        testRead(design, progressBar);
-        testWrite(design, progressBar);
-    }
-
 }
\ No newline at end of file
index f71fdc83ee8d8d38cf8bb1be692cb7322c378269..9d61656801cf7bb7b1b1951484aab3a870d948f5 100644 (file)
@@ -56,15 +56,4 @@ public class RichTextAreaDeclarativeTest extends
     public void testWriteEmpty() {
         testWrite("<v-rich-text-area />", new RichTextArea());
     }
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-rich-text-area readonly style-name='v-richtextarea-readonly'>Hello World!</v-text-area>";
-        RichTextArea ta = new RichTextArea();
-        ta.setValue("Hello World!");
-        ta.setReadOnly(true);
-
-        testRead(design, ta);
-        testWrite(design, ta);
-    }
 }
index 0c2ac6bed9b5cf794a0a31f3db338e24b56a4ac9..9ef28afb82b73c4b5382ffe1deee70679bfbf02d 100644 (file)
@@ -63,19 +63,4 @@ public class SliderDeclarativeTest extends DeclarativeTestBase<Slider> {
         testRead(design, expected);
         testWrite(design, expected);
     }
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-slider readonly min=10 max=20 resolution=1 value=12.3>";
-
-        Slider expected = new Slider();
-        expected.setMin(10.0);
-        expected.setMax(20.0);
-        expected.setResolution(1);
-        expected.setValue(12.3);
-        expected.setReadOnly(true);
-
-        testRead(design, expected);
-        testWrite(design, expected);
-    }
 }
index f70f1fde98bc474d2485fac8e741f86446152d30..bed88512049f83bf823ec04d196a8a490b626e4d 100644 (file)
@@ -58,17 +58,6 @@ public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> {
         read.writeDesign(root, dc);
 
         Assert.assertEquals("&amp;amp; Test", root.html());
-    }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-text-area readonly rows=6 wordwrap=false>Hello World!</v-text-area>";
-        TextArea ta = new TextArea();
-        ta.setRows(6);
-        ta.setWordwrap(false);
-        ta.setValue("Hello World!");
-        ta.setReadOnly(true);
-        testRead(design, ta);
-        testWrite(design, ta);
     }
 }
index d545ee5a1a6dd3c50eea954a63b03f24a2cca0da..b4e7f9dae3416e2f0683614ee29c1a983bac8808 100644 (file)
@@ -44,14 +44,4 @@ public class TextFieldDeclarativeTest extends DeclarativeTestBase<TextField> {
         testRead(design, tf);
         testWrite(design, tf);
     }
-
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<v-text-field readonly=\"\" value=\"test value\"/>";
-        TextField tf = new TextField();
-        tf.setValue("test value");
-        tf.setReadOnly(true);
-        testRead(design, tf);
-        testWrite(design, tf);
-    }
 }