summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2015-09-10 14:09:32 +0300
committerJohn Ahlroos <john@vaadin.com>2015-09-25 12:15:37 +0300
commit5e9209421ce92e16531299c8c4be5fdd412bb513 (patch)
treea45264968949607b4111c99390933dadd3bf575c /server/src/com/vaadin
parentccad63a4aa12a00016ac29c5b612f6f59edc379b (diff)
downloadvaadin-framework-5e9209421ce92e16531299c8c4be5fdd412bb513.tar.gz
vaadin-framework-5e9209421ce92e16531299c8c4be5fdd412bb513.zip
Parse readonly values for AbstractFields correctly #18850
Change-Id: I6f7d8731d185fe1c88e861435a401d887b2defbe
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java32
-rw-r--r--server/src/com/vaadin/ui/AbstractSelect.java30
-rw-r--r--server/src/com/vaadin/ui/CheckBox.java5
-rw-r--r--server/src/com/vaadin/ui/DateField.java2
-rw-r--r--server/src/com/vaadin/ui/PasswordField.java2
-rw-r--r--server/src/com/vaadin/ui/ProgressBar.java5
-rw-r--r--server/src/com/vaadin/ui/RichTextArea.java2
-rw-r--r--server/src/com/vaadin/ui/Slider.java7
-rw-r--r--server/src/com/vaadin/ui/TextArea.java3
-rw-r--r--server/src/com/vaadin/ui/TextField.java5
10 files changed, 64 insertions, 29 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index cf14d1cb96..61f58157ea 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<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();
}
}
@@ -459,15 +461,35 @@ 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)
- 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..3a427562d2 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;
@@ -701,22 +703,28 @@ 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 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<Object>(), repaintIsNotNeeded);
- } else if (Collection.class.isAssignableFrom(newValue.getClass())) {
+ if (newFieldValue == null) {
+ super.setValue(new LinkedHashSet<Object>(), repaintIsNotNeeded,
+ ignoreReadOnly);
+ } else if (Collection.class.isAssignableFrom(newFieldValue
+ .getClass())) {
super.setValue(new LinkedHashSet<Object>(
- (Collection<?>) newValue), repaintIsNotNeeded);
+ (Collection<?>) newFieldValue), repaintIsNotNeeded,
+ ignoreReadOnly);
}
- } else if (newValue == null || items.containsId(newValue)) {
- super.setValue(newValue, repaintIsNotNeeded);
+ } else if (newFieldValue == null || items.containsId(newFieldValue)) {
+ super.setValue(newFieldValue, repaintIsNotNeeded, ignoreReadOnly);
}
}
@@ -2196,9 +2204,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
}
if (!selected.isEmpty()) {
if (isMultiSelect()) {
- setValue(selected);
+ setValue(selected, false, true);
} else if (selected.size() == 1) {
- setValue(selected.iterator().next());
+ setValue(selected.iterator().next(), false, true);
} 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 e98a2b61b9..8b31edcbb4 100644
--- a/server/src/com/vaadin/ui/CheckBox.java
+++ b/server/src/com/vaadin/ui/CheckBox.java
@@ -221,8 +221,9 @@ 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));
+ this.setValue(
+ DesignAttributeHandler.readAttribute("checked",
+ design.attributes(), Boolean.class), false, true);
}
}
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java
index 422b1ffdd8..052539cd28 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);
+ this.setValue(date, false, true);
}
}
diff --git a/server/src/com/vaadin/ui/PasswordField.java b/server/src/com/vaadin/ui/PasswordField.java
index ff3b1fea1f..385649c318 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));
+ String.class), false, true);
}
}
diff --git a/server/src/com/vaadin/ui/ProgressBar.java b/server/src/com/vaadin/ui/ProgressBar.java
index 89baac1e64..d38067d51e 100644
--- a/server/src/com/vaadin/ui/ProgressBar.java
+++ b/server/src/com/vaadin/ui/ProgressBar.java
@@ -159,8 +159,9 @@ 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));
+ setValue(
+ DesignAttributeHandler.readAttribute("value",
+ design.attributes(), Float.class), false, true);
}
}
diff --git a/server/src/com/vaadin/ui/RichTextArea.java b/server/src/com/vaadin/ui/RichTextArea.java
index 7c23cce5cb..eff669c4c6 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());
+ setValue(design.html(), false, true);
}
@Override
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index 15c94b6d3c..6b0880efd5 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -370,9 +370,10 @@ public class Slider extends AbstractField<Double> {
if (attr.hasKey("vertical")) {
setOrientation(SliderOrientation.VERTICAL);
}
- if (!attr.get("value").isEmpty()) {
- setValue(DesignAttributeHandler.readAttribute("value", attr,
- Double.class));
+ if (attr.hasKey("value")) {
+ Double newFieldValue = DesignAttributeHandler.readAttribute(
+ "value", attr, Double.class);
+ setValue(newFieldValue, false, true);
}
}
diff --git a/server/src/com/vaadin/ui/TextArea.java b/server/src/com/vaadin/ui/TextArea.java
index 75ecc19d40..c2af125338 100644
--- a/server/src/com/vaadin/ui/TextArea.java
+++ b/server/src/com/vaadin/ui/TextArea.java
@@ -146,7 +146,8 @@ public class TextArea extends AbstractTextField {
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
- setValue(DesignFormatter.unencodeFromTextNode(design.html()));
+ setValue(DesignFormatter.unencodeFromTextNode(design.html()), false,
+ true);
}
/*
diff --git a/server/src/com/vaadin/ui/TextField.java b/server/src/com/vaadin/ui/TextField.java
index 2a61e93211..8772f95f3d 100644
--- a/server/src/com/vaadin/ui/TextField.java
+++ b/server/src/com/vaadin/ui/TextField.java
@@ -115,8 +115,9 @@ public class TextField extends AbstractTextField {
super.readDesign(design, designContext);
Attributes attr = design.attributes();
if (attr.hasKey("value")) {
- setValue(DesignAttributeHandler.readAttribute("value", attr,
- String.class));
+ String newFieldValue = DesignAttributeHandler.readAttribute(
+ "value", attr, String.class);
+ setValue(newFieldValue, false, true);
}
}