From 379bc6f79767d2c4a3fda3b8ecec8474740463a6 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 21 Jun 2012 11:27:55 +0300 Subject: [PATCH] Call attach only once for children (#9005) --- src/com/vaadin/ui/CustomField.java | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/com/vaadin/ui/CustomField.java b/src/com/vaadin/ui/CustomField.java index 269f24fb2c..0998c11612 100644 --- a/src/com/vaadin/ui/CustomField.java +++ b/src/com/vaadin/ui/CustomField.java @@ -62,21 +62,18 @@ public abstract class CustomField extends AbstractField implements */ @Override public void attach() { - root = getContent(); - getContent().setParent(this); - fireComponentAttachEvent(getContent()); + // First call super attach to notify all children (none if content has + // not yet been created) super.attach(); - } - /** - * Notifies the content that the {@link CustomField} is detached from a - * window. - * - * @see com.vaadin.ui.Component#detach() - */ - @Override - public void detach() { - super.detach(); + // If the content has not yet been created, we create and attach it at + // this point. + if (root == null) { + // Ensure content is created and its parent is set. + // The getContent() call creates the content and attaches the + // content + fireComponentAttachEvent(getContent()); + } } /** @@ -87,6 +84,7 @@ public abstract class CustomField extends AbstractField implements protected Component getContent() { if (null == root) { root = initContent(); + root.setParent(this); } return root; } -- 2.39.5