summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/com/vaadin/data/fieldgroup/FieldGroup.java')
-rw-r--r--server/src/com/vaadin/data/fieldgroup/FieldGroup.java32
1 files changed, 24 insertions, 8 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
index c5aab5a053..5a4e877554 100644
--- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
@@ -211,7 +211,8 @@ public class FieldGroup implements Serializable {
public void setReadOnly(boolean fieldsReadOnly) {
readOnly = fieldsReadOnly;
for (Field<?> field : getFields()) {
- if (!field.getPropertyDataSource().isReadOnly()) {
+ if (field.getPropertyDataSource() == null
+ || !field.getPropertyDataSource().isReadOnly()) {
field.setReadOnly(fieldsReadOnly);
} else {
field.setReadOnly(true);
@@ -244,15 +245,13 @@ public class FieldGroup implements Serializable {
* @param propertyId
* The propertyId to bind to the field
* @throws BindException
- * If the property id is already bound to another field by this
- * field binder
+ * If the field is null or the property id is already bound to
+ * another field by this field binder
*/
public void bind(Field<?> field, Object propertyId) throws BindException {
- if (propertyIdToField.containsKey(propertyId)
- && propertyIdToField.get(propertyId) != field) {
- throw new BindException("Property id " + propertyId
- + " is already bound to another field");
- }
+ throwIfFieldIsNull(field, propertyId);
+ throwIfPropertyIdAlreadyBound(field, propertyId);
+
fieldToPropertyId.put(field, propertyId);
propertyIdToField.put(propertyId, field);
if (itemDataSource == null) {
@@ -264,6 +263,23 @@ public class FieldGroup implements Serializable {
configureField(field);
}
+ private void throwIfFieldIsNull(Field<?> field, Object propertyId) {
+ if (field == null) {
+ throw new BindException(
+ String.format(
+ "Cannot bind property id '%s' to a null field.",
+ propertyId));
+ }
+ }
+
+ private void throwIfPropertyIdAlreadyBound(Field<?> field, Object propertyId) {
+ if (propertyIdToField.containsKey(propertyId)
+ && propertyIdToField.get(propertyId) != field) {
+ throw new BindException("Property id " + propertyId
+ + " is already bound to another field");
+ }
+ }
+
private <T> Property.Transactional<T> wrapInTransactionalProperty(
Property<T> itemProperty) {
return new TransactionalPropertyWrapper<T>(itemProperty);