From 6d75a89e8d16e0fd1370fe080a5b5b78d1f4679d Mon Sep 17 00:00:00 2001 From: Matti Hosio Date: Wed, 17 Dec 2014 14:08:59 +0200 Subject: Do not throw exception when trying to bind a preinitialized instance field (#7749) Change-Id: I8b40e667d03b63e05f006e7cedf108345591d118 --- server/src/com/vaadin/ui/declarative/DesignContext.java | 9 +++++++-- server/src/com/vaadin/ui/declarative/FieldBinder.java | 15 ++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'server/src/com/vaadin/ui/declarative') diff --git a/server/src/com/vaadin/ui/declarative/DesignContext.java b/server/src/com/vaadin/ui/declarative/DesignContext.java index 25765611aa..0ce269261b 100644 --- a/server/src/com/vaadin/ui/declarative/DesignContext.java +++ b/server/src/com/vaadin/ui/declarative/DesignContext.java @@ -437,11 +437,12 @@ public class DesignContext implements Serializable { * at the given component. Also registers the componentid, localId and * caption of the given component and all its children to the context * - * * @param component * The component to be synchronized from design * @param componentDesign * The html tree node containing the description of the component + * @throws DesignException + * if the design contains duplicate local or global ids */ public void synchronizeAndRegister(Component component, Element componentDesign) { @@ -463,7 +464,11 @@ public class DesignContext implements Serializable { // from the attributes of componentDesign if (attributes.hasKey(LOCAL_ID_ATTRIBUTE)) { String localId = attributes.get(LOCAL_ID_ATTRIBUTE); - mapLocalId(localId, component); // two-way map + boolean mappingExists = mapLocalId(localId, component); + if (mappingExists) { + throw new DesignException( + "the following local id is not unique: " + localId); + } } // caption: a property of a component, possibly not unique String caption = component.getCaption(); diff --git a/server/src/com/vaadin/ui/declarative/FieldBinder.java b/server/src/com/vaadin/ui/declarative/FieldBinder.java index af82d9c58c..fcc78db414 100644 --- a/server/src/com/vaadin/ui/declarative/FieldBinder.java +++ b/server/src/com/vaadin/ui/declarative/FieldBinder.java @@ -135,8 +135,6 @@ public class FieldBinder implements Serializable { /** * Tries to bind the given {@link Component} instance to a member field of * the bind target. The fields are matched based on localId, id and caption. - * If a field is already bound (not null), {@link FieldBindingException} is - * thrown. * * @param instance * the instance to be bound to a field @@ -197,14 +195,13 @@ public class FieldBinder implements Serializable { Object fieldValue = ReflectTools.getJavaFieldValue(bindTarget, field); if (fieldValue != null) { - getLogger().severe( - "The field with identifier \"" + identifier - + "\" already mapped"); - throw new FieldBindingException( - "Duplicate identifier found for a field: " + fieldName); + getLogger().fine( + "The field \"" + fieldName + + "\" was already mapped. Ignoring."); + } else { + // set the field value + ReflectTools.setJavaFieldValue(bindTarget, field, instance); } - // set the field value - ReflectTools.setJavaFieldValue(bindTarget, field, instance); return true; } catch (IllegalAccessException e) { throw new FieldBindingException("Field binding failed", e); -- cgit v1.2.3