]> source.dussan.org Git - vaadin-framework.git/commitdiff
Call attach only once for children (#9005)
authorArtur Signell <artur@vaadin.com>
Thu, 21 Jun 2012 08:27:55 +0000 (11:27 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 21 Jun 2012 14:11:33 +0000 (17:11 +0300)
src/com/vaadin/ui/CustomField.java

index 269f24fb2cb5a6fac57f7cc23f8fe85457121c06..0998c11612db297f7b6812aeadb1017c4facfa19 100644 (file)
@@ -62,21 +62,18 @@ public abstract class CustomField<T> extends AbstractField<T> 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<T> extends AbstractField<T> implements
     protected Component getContent() {
         if (null == root) {
             root = initContent();
+            root.setParent(this);
         }
         return root;
     }