From f0756724f0feb641b2f3ea9c5195457aebb4b872 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 5 Nov 2010 12:20:07 +0000 Subject: [PATCH] fixes #5955. A bit more intelligent removal of fields from Form + a method that can be overridden for a custom logic. svn changeset:15880/svn branch:6.5 --- src/com/vaadin/ui/Form.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 0e487da603..8aa06d34cc 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -639,7 +639,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, if (field != null) { propertyIds.remove(id); fields.remove(id); - layout.removeComponent(field); + detachField(field); field.removeListener(fieldValueChangeListener); return true; } @@ -647,6 +647,25 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, return false; } + /** + * Called when a form field is detached from a Form. Typically when a new + * Item is assigned to Form via {@link #setItemDataSource(Item)} * + *

+ * Override this method to control how the fields are removed from the + * layout. + *

+ * + * + * @param field + * the field to be detached from the forms layout. + */ + protected void detachField(final Field field) { + Component p = field.getParent(); + if (p instanceof ComponentContainer) { + ((ComponentContainer) p).removeComponent(field); + } + } + /** * Removes all properties and fields from the form. * @@ -781,7 +800,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, final Object[] properties = propertyIds.toArray(); for (int i = 0; i < properties.length; i++) { Field f = getField(properties[i]); - layout.removeComponent(f); + detachField(f); if (newLayout instanceof CustomLayout) { ((CustomLayout) newLayout).addComponent(f, properties[i].toString()); -- 2.39.5