Author: jcompagner
Date: Mon May 14 16:27:12 2007
New Revision: 538014

URL: http://svn.apache.org/viewvc?view=rev&rev=538014
Log:
onAttach fixes so that everything is now first sent in attaching. then onAttach 
is called
then attings is set to false and attached to true for all the childs.
so done now in 3 steps.

also beforeRender. first the childs are called for beforeRender then onRedering 
is set for the component

Modified:
    
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
    
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java?view=diff&rev=538014&r1=538013&r2=538014
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
 Mon May 14 16:27:12 2007
@@ -599,9 +599,9 @@
        /** Reserved subclass-definable flag bit */
        protected static final int FLAG_RESERVED8 = 0x80000;
 
-       private static final int FLAG_ATTACH_SUPER_CALL_VERIFIED = 0x10000000;
-       private static final int FLAG_ATTACHED = 0x20000000;
-       private static final int FLAG_ATTACHING = 0x40000000;
+       static final int FLAG_ATTACH_SUPER_CALL_VERIFIED = 0x10000000;
+       static final int FLAG_ATTACHED = 0x20000000;
+       static final int FLAG_ATTACHING = 0x40000000;
        private static final int FLAG_DETACHING = 0x80000000;
 
        private static final int FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED = 
0x1000000;
@@ -2931,16 +2931,7 @@
         * last in onAttach() chain no matter where user places the
         * <code>super.onAttach()</code> call
         */
-       void attachChildren()
-       {
-               // noop
-       }
-
-       /**
-        * Attaches the component. This is called when the page is starting to 
be
-        * used for rendering or when a component listener call is executed on 
it.
-        */
-       public final void attach()
+       void internalAttach2()
        {
                if (!getFlag(FLAG_ATTACHED))
                {
@@ -2954,11 +2945,19 @@
                        }
                        setFlag(FLAG_ATTACHING, false);
                        setFlag(FLAG_ATTACHED, true);
-                       attachChildren();
                }
        }
 
        /**
+        * Attaches the component. This is called when the page is starting to 
be
+        * used for rendering or when a component listener call is executed on 
it.
+        */
+       public final void attach()
+       {
+               internalAttach2();
+       }
+
+       /**
         * @return true if this component is attached
         */
        protected final boolean isAttached()
@@ -3044,8 +3043,8 @@
                                                                + 
getClass().getName()
                                                                + " has not 
called super.onBeforeRender() in the override of onBeforeRender() method");
                        }
-                       setFlag(FLAG_RENDERING, true);
                        onBeforeRenderChildren();
+                       setFlag(FLAG_RENDERING, true);
                }
        }
 

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?view=diff&rev=538014&r1=538013&r2=538014
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
 Mon May 14 16:27:12 2007
@@ -1351,29 +1351,54 @@
                this.markupStream = markupStream;
        }
 
-       void attachChildren()
+       final void internalAttach2()
        {
-               super.attachChildren();
-               try
+               if (!getFlag(FLAG_ATTACHED))
                {
-                       // Loop through child components
-                       final int size = children_size();
-                       for (int i = 0; i < size; i++)
+                       setFlag(FLAG_ATTACHING, true);
+                       visitChildren(new IVisitor()
                        {
-                               // Get next child
-                               final Component child = children_get(i);
-
-                               // Call begin request on the child
-                               child.attach();
+                               public Object component(Component component)
+                               {
+                                       component.setFlag(FLAG_ATTACHING, true);
+                                       return IVisitor.CONTINUE_TRAVERSAL;
+                               }
+                       });
+                       setFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED, false);
+                       onAttach();
+                       if (!getFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED))
+                       {
+                               throw new IllegalStateException("Component " + 
this + " of type " + getClass().getName() + " has not been properly attached.  "
+                                               + "Something in its class 
hierarchy has failed to call super.onAttach() in an override of onAttach() 
method");
                        }
-               }
-               catch (RuntimeException ex)
-               {
-                       if (ex instanceof WicketRuntimeException)
-                               throw ex;
-                       else
-                               throw new WicketRuntimeException("Error 
attaching this container for rendering: "
-                                               + this, ex);
+                       
+                       visitChildren(new IVisitor()
+                       {
+                               public Object component(Component component)
+                               {
+                                       
component.setFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED, false);
+                                       component.onAttach();
+                                       if 
(!component.getFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED))
+                                       {
+                                               throw new 
IllegalStateException("Component " + component + " of type " + 
component.getClass().getName() + " has not been properly attached.  "
+                                                               + "Something in 
its class hierarchy has failed to call super.onAttach() in an override of 
onAttach() method");
+                                       }
+                                       return IVisitor.CONTINUE_TRAVERSAL;
+                               }
+                       });
+                       
+                       visitChildren(new IVisitor()
+                       {
+                               public Object component(Component component)
+                               {
+                                       component.setFlag(FLAG_ATTACHING, 
false);
+                                       component.setFlag(FLAG_ATTACHED, true);
+                                       return IVisitor.CONTINUE_TRAVERSAL;
+                               }
+                       });
+
+                       setFlag(FLAG_ATTACHING, false);
+                       setFlag(FLAG_ATTACHED, true);
                }
        }
 


Reply via email to