From 76b42e680f0f409f253a3aa8499a18fd09329957 Mon Sep 17 00:00:00 2001
From: John Ahlroos
Date: Thu, 10 Sep 2015 14:09:32 +0300
Subject: [PATCH] Parse readonly values for AbstractFields correctly (#18850)
Change-Id: I1128ec0bda9b0fdad721f084c1e78cfe78e984f2
---
server/src/com/vaadin/ui/AbstractField.java | 32 ++++++++++++---
server/src/com/vaadin/ui/AbstractSelect.java | 31 +++++++++-----
server/src/com/vaadin/ui/CheckBox.java | 5 ++-
server/src/com/vaadin/ui/DateField.java | 2 +-
server/src/com/vaadin/ui/PasswordField.java | 2 +-
server/src/com/vaadin/ui/ProgressBar.java | 5 ++-
server/src/com/vaadin/ui/RichTextArea.java | 2 +-
server/src/com/vaadin/ui/Slider.java | 7 ++--
server/src/com/vaadin/ui/TextArea.java | 3 +-
server/src/com/vaadin/ui/TextField.java | 5 ++-
.../checkbox/CheckboxDeclarativeTest.java | 10 +++++
.../combobox/ComboBoxDeclarativeTest.java | 16 ++++++++
.../datefield/DateFieldDeclarativeTest.java | 12 ++++++
.../NativeSelectDeclarativeTest.java | 16 ++++++++
.../PasswordFieldDeclarativeTest.java | 40 +++++++++++++++++++
.../ProgressBarDeclarativeTest.java | 14 ++++++-
.../RichTextAreaDeclarativeTest.java | 11 +++++
.../slider/SliderDeclarativeTest.java | 15 +++++++
.../textarea/TextAreaDeclarativeTest.java | 11 +++++
.../textfield/TextFieldDeclarativeTest.java | 10 +++++
20 files changed, 219 insertions(+), 30 deletions(-)
create mode 100644 server/tests/src/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index cf14d1cb96..e69322b1cc 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -264,7 +264,9 @@ public abstract class AbstractField 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();
}
}
@@ -459,15 +461,35 @@ public abstract class AbstractField 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 7.5.7
+ * @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)
- throws Property.ReadOnlyException, Converter.ConversionException,
- InvalidValueException {
+ protected void setValue(T newFieldValue, boolean repaintIsNotNeeded,
+ boolean ignoreReadOnly) throws Property.ReadOnlyException,
+ Converter.ConversionException, InvalidValueException {
if (!SharedUtil.equals(newFieldValue, getInternalValue())) {
// Read only fields can not be changed
- if (isReadOnly()) {
+ if (!ignoreReadOnly && 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 bbd486a8f9..ee4cf87ed3 100644
--- a/server/src/com/vaadin/ui/AbstractSelect.java
+++ b/server/src/com/vaadin/ui/AbstractSelect.java
@@ -34,8 +34,10 @@ 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;
@@ -697,26 +699,33 @@ public abstract class AbstractSelect extends AbstractField
*
+ * @since 7.5.7
* @param newValue
* 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 newValue, boolean repaintIsNotNeeded)
- throws Property.ReadOnlyException {
-
+ protected void setValue(Object newFieldValue, boolean repaintIsNotNeeded,
+ boolean ignoreReadOnly)
+ throws com.vaadin.data.Property.ReadOnlyException,
+ ConversionException, InvalidValueException {
if (isMultiSelect()) {
- if (newValue == null) {
- super.setValue(new LinkedHashSet