Author: ivaynberg
Date: Sun Mar 25 23:19:51 2007
New Revision: 522435

URL: http://svn.apache.org/viewvc?view=rev&rev=522435
Log:
better detach behavior

Modified:
    
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java

Modified: 
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java?view=diff&rev=522435&r1=522434&r2=522435
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/Component.java
 Sun Mar 25 23:19:51 2007
@@ -2769,17 +2769,29 @@
         */
        public final void detach()
        {
-               setFlag(FLAG_DETACHING, true);
-               onDetach();
-               if (getFlag(FLAG_DETACHING))
+               if (getFlag(FLAG_ATTACHED))
                {
-                       throw new 
IllegalStateException(Component.class.getName()
-                                       + " has not been properly detached. 
Something in the hierarchy of "
-                                       + getClass().getName()
-                                       + " has not called super.onDetach() in 
the override of onDetach() method");
+                       // if the component has been previously attached via 
attach()
+                       // detach it now
+                       setFlag(FLAG_DETACHING, true);
+                       onDetach();
+                       if (getFlag(FLAG_DETACHING))
+                       {
+                               throw new 
IllegalStateException(Component.class.getName()
+                                               + " has not been properly 
detached. Something in the hierarchy of "
+                                               + getClass().getName()
+                                               + " has not called 
super.onDetach() in the override of onDetach() method");
+                       }
+                       setFlag(FLAG_ATTACHED, false);
                }
-               setFlag(FLAG_ATTACHED, false);
+               
+               // always detach models because they can be attached without the
+               // component. eg component has a compoundpropertymodel and one 
of its
+               // children component's getmodelobject is called
+               detachModels();
 
+               // always detach children because components can be attached
+               // independently of their parents
                detachChildren();
        }
 


Reply via email to