diff options
Diffstat (limited to 'src/com/vaadin')
-rw-r--r-- | src/com/vaadin/ui/Form.java | 23 |
1 files 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; } @@ -648,6 +648,25 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, } /** + * Called when a form field is detached from a Form. Typically when a new + * Item is assigned to Form via {@link #setItemDataSource(Item)} * + * <p> + * Override this method to control how the fields are removed from the + * layout. + * </p> + * + * + * @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. * * @return the Success of the operation. Removal of all fields succeeded if @@ -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()); |