diff options
author | Markus Koivisto <markus@vaadin.com> | 2015-09-30 16:22:11 +0300 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-09-30 16:22:11 +0300 |
commit | 2fa06db5f70236fdbd93b2c66efd07aa0e880c03 (patch) | |
tree | 4821e06011cea1f14fd122d56d970bd18158ab7c | |
parent | b0b8f1a21b01089d0ddef954518dfc7ec02bddc1 (diff) | |
download | vaadin-framework-2fa06db5f70236fdbd93b2c66efd07aa0e880c03.tar.gz vaadin-framework-2fa06db5f70236fdbd93b2c66efd07aa0e880c03.zip |
Revert "Parse readonly values for AbstractFields correctly #18850"
This reverts commit 5e9209421ce92e16531299c8c4be5fdd412bb513.
20 files changed, 29 insertions, 217 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 61f58157ea..cf14d1cb96 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -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 { diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 3a427562d2..bbd486a8f9 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -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"); diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 8b31edcbb4..e98a2b61b9 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -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)); } } diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index 052539cd28..422b1ffdd8 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -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); } } diff --git a/server/src/com/vaadin/ui/PasswordField.java b/server/src/com/vaadin/ui/PasswordField.java index 385649c318..ff3b1fea1f 100644 --- a/server/src/com/vaadin/ui/PasswordField.java +++ b/server/src/com/vaadin/ui/PasswordField.java @@ -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)); } } diff --git a/server/src/com/vaadin/ui/ProgressBar.java b/server/src/com/vaadin/ui/ProgressBar.java index d38067d51e..89baac1e64 100644 --- a/server/src/com/vaadin/ui/ProgressBar.java +++ b/server/src/com/vaadin/ui/ProgressBar.java @@ -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)); } } diff --git a/server/src/com/vaadin/ui/RichTextArea.java b/server/src/com/vaadin/ui/RichTextArea.java index eff669c4c6..7c23cce5cb 100644 --- a/server/src/com/vaadin/ui/RichTextArea.java +++ b/server/src/com/vaadin/ui/RichTextArea.java @@ -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 diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index 6b0880efd5..15c94b6d3c 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/server/src/com/vaadin/ui/Slider.java @@ -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)); } } diff --git a/server/src/com/vaadin/ui/TextArea.java b/server/src/com/vaadin/ui/TextArea.java index c2af125338..75ecc19d40 100644 --- a/server/src/com/vaadin/ui/TextArea.java +++ b/server/src/com/vaadin/ui/TextArea.java @@ -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())); } /* diff --git a/server/src/com/vaadin/ui/TextField.java b/server/src/com/vaadin/ui/TextField.java index 8772f95f3d..2a61e93211 100644 --- a/server/src/com/vaadin/ui/TextField.java +++ b/server/src/com/vaadin/ui/TextField.java @@ -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)); } } diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java index 3ac81b2a84..6162e41494 100644 --- a/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java @@ -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); - } } diff --git a/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java index d49d2b79e2..e9d66b478b 100644 --- a/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java @@ -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'>"; } diff --git a/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java index c3fc4bf723..5058cf5a5f 100644 --- a/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java @@ -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); - } } diff --git a/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java index 140335e136..8f1b995cc6 100644 --- a/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java @@ -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 index 6934d2011c..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java +++ /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); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java index 6e42d0c1dd..c98883a4a7 100644 --- a/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java @@ -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 diff --git a/server/tests/src/com/vaadin/tests/server/component/richtextarea/RichTextAreaDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/richtextarea/RichTextAreaDeclarativeTest.java index f71fdc83ee..9d61656801 100644 --- a/server/tests/src/com/vaadin/tests/server/component/richtextarea/RichTextAreaDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/richtextarea/RichTextAreaDeclarativeTest.java @@ -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); - } } diff --git a/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java index 0c2ac6bed9..9ef28afb82 100644 --- a/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java @@ -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); - } } diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java index f70f1fde98..bed8851204 100644 --- a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java @@ -58,17 +58,6 @@ public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> { read.writeDesign(root, dc); Assert.assertEquals("&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); } } diff --git a/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java index d545ee5a1a..b4e7f9dae3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java @@ -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); - } } |