Author: jcompagner
Date: Mon Mar 24 07:24:53 2008
New Revision: 640424

URL: http://svn.apache.org/viewvc?rev=640424&view=rev
Log:
fix for WICKET-1438 (page.onDetach results in error in RequestCycle.detach())
this also fixes and improves the body/header check fix: WICKET-1105

Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/WebPage.java

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?rev=640424&r1=640423&r2=640424&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java 
(original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java 
Mon Mar 24 07:24:53 2008
@@ -1036,9 +1036,9 @@
                // clean up target stack; calling detach has effects like
                // NOTE: don't remove the targets as testing code might need 
them
                // furthermore, the targets will be gc-ed with this cycle too
-               for (Iterator iter = requestTargets.iterator(); iter.hasNext();)
+               for (int i = 0; i < requestTargets.size(); i++)
                {
-                       IRequestTarget target = (IRequestTarget)iter.next();
+                       IRequestTarget target = 
(IRequestTarget)requestTargets.get(i);
                        if (target != null)
                        {
                                try
@@ -1227,10 +1227,10 @@
                                        // has to result in a request target
                                        if (target == null)
                                        {
-                                               this.handled = false;
+                                               handled = false;
                                                currentStep = DONE;
-                                               //throw new 
WicketRuntimeException(
-                                               //      "the processor did not 
resolve to any request target");
+                                               // throw new 
WicketRuntimeException(
+                                               // "the processor did not 
resolve to any request target");
                                        }
                                        // Add (inserting at the bottom) in 
case before or during
                                        // target resolving one or more request 
targets were pushed
@@ -1290,17 +1290,18 @@
        }
 
        /**
-        * INTERNAL. This method is not part of public Wicket Api. Do not call 
it.
-        * Returns whether wicket handled this request or not (i.e. when no 
request target was found). 
+        * INTERNAL. This method is not part of public Wicket Api. Do not call 
it. Returns whether
+        * wicket handled this request or not (i.e. when no request target was 
found).
+        * 
         * @return true if wicket handled this request, false otherwise
         */
        public boolean wasHandled()
        {
                return handled;
        }
-       
+
        private boolean handled = true;
-       
+
        /**
         * Loop through the processing steps starting from the current one.
         */
@@ -1441,7 +1442,7 @@
         * MetaDataEntry array.
         */
        private MetaDataEntry[] metaData;
-       
+
        /**
         * Sets the metadata for this request cycle using the given key. If the 
metadata object is not
         * of the correct type for the metadata key, an 
IllegalArgumentException will be thrown. For

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/WebPage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/WebPage.java?rev=640424&r1=640423&r2=640424&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/WebPage.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/WebPage.java
 Mon Mar 24 07:24:53 2008
@@ -56,7 +56,7 @@
  * a no-arg constructor or with a constructor that accepts a PageParameters 
argument (which wraps
  * any query string parameters for a request). In case the page has both 
constructors, the
  * constructor with PageParameters will be used.
- *
+ * 
  * @author Jonathan Locke
  * @author Eelco Hillenius
  * @author Juergen Donnerstag
@@ -79,7 +79,7 @@
 
                /**
                 * Construct.
-                *
+                * 
                 * @param webPage
                 */
                PageMapChecker(WebPage webPage)
@@ -220,10 +220,10 @@
         * Note that nothing is done with the page parameters argument. This 
constructor is provided so
         * that tools such as IDEs will include it their list of suggested 
constructors for derived
         * classes.
-        *
+        * 
         * Please call this constructor (or the one with the pagemap) if you 
want to remember the
         * pageparameters [EMAIL PROTECTED] #getPageParameters()}. So that they 
are reused for stateless links.
-        *
+        * 
         * @param parameters
         *            Wrapped query string parameters.
         */
@@ -241,10 +241,10 @@
         * Note that nothing is done with the page parameters argument. This 
constructor is provided so
         * that tools such as IDEs will include it their list of suggested 
constructors for derived
         * classes.
-        *
+        * 
         * Please call this constructor (or the one without the pagemap) if you 
want to remember the
         * pageparameters [EMAIL PROTECTED] #getPageParameters()}. So that they 
are reused for stateless links.
-        *
+        * 
         * @param pageMap
         *            The pagemap where the webpage needs to be constructed in.
         * @param parameters
@@ -261,7 +261,7 @@
         * markup language, such as VXML, would require the creation of a 
different Page subclass in an
         * appropriate package under org.apache.wicket.markup. To support VXML 
(voice markup), one might
         * create the package org.apache.wicket.markup.vxml and a subclass of 
Page called VoicePage.
-        *
+        * 
         * @return Markup type for HTML
         */
        public String getMarkupType()
@@ -272,18 +272,18 @@
        /**
         * This method is called when the compressing coding and response 
strategies are configured in
         * your Application object like this:
-        *
+        * 
         * <pre>
         * protected IRequestCycleProcessor newRequestCycleProcessor()
         * {
         *      return new UrlCompressingWebRequestProcessor();
         * }
         * </pre>
-        *
+        * 
         * @return The URLCompressor for this webpage.
-        *
+        * 
         * @since 1.2
-        *
+        * 
         * @see UrlCompressingWebRequestProcessor
         * @see UrlCompressor
         */
@@ -345,15 +345,15 @@
        /**
         * Subclasses can override this to set there headers when the Page is 
being served. By default 2
         * headers will be set
-        *
+        * 
         * <pre>
         * response.setHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);
         * response.setHeader(&quot;Cache-Control&quot;, &quot;no-cache, 
max-age=0, must-revalidate&quot;);
         * </pre>
-        *
+        * 
         * So if a Page wants to control this or doesn't want to set this info 
it should override this
         * method and don't call super.
-        *
+        * 
         * @param response
         *            The WebResponse where set(Date)Header can be called on.
         */
@@ -374,7 +374,7 @@
 
        /**
         * Creates and returns a bookmarkable link to this application's home 
page.
-        *
+        * 
         * @param id
         *            Name of link
         * @return Link to home page for this application
@@ -384,75 +384,77 @@
                return new BookmarkablePageLink(id, 
getApplication().getHomePage());
        }
 
-       /**
-        *
-        * @see org.apache.wicket.Component#onDetach()
-        */
-       protected void onDetach()
+       protected void onAfterRender()
        {
-               // This code can not go into HtmlHeaderContainer as
-               // header.onEndRequest() is executed inside an iterator
-               // and you can only call container.remove() which
-               // is != iter.remove(). And the iterator is not available
-               // inside onEndRequest(). Obviously WebPage.onEndRequest()
-               // is invoked outside the iterator loop.
-               HtmlHeaderContainer header = 
(HtmlHeaderContainer)get(HtmlHeaderSectionHandler.HEADER_ID);
-               if (header != null)
-               {
-                       this.remove(header);
-               }
-               else if (getApplication().getConfigurationType() == 
Application.DEVELOPMENT)
+               super.onAfterRender();
+               if (getApplication().getConfigurationType() == 
Application.DEVELOPMENT)
                {
-                       // the markup must at least contain a <body> tag for 
wicket to automatically
-                       // create a HtmlHeaderContainer. Log an error if no 
header container
-                       // was created but any of the components or behavior 
want to contribute
-                       // something to the header.
-                       header = new 
HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
-                       add(header);
-
-                       Response orgResponse = getRequestCycle().getResponse();
-                       try
+                       HtmlHeaderContainer header = 
(HtmlHeaderContainer)visitChildren(new IVisitor()
                        {
-                               final StringResponse response = new 
StringResponse();
-                               getRequestCycle().setResponse(response);
-
-                               // Render all header sections of all components 
on the page
-                               renderHead(header);
-
-                               // Make sure all Components interested in 
contributing to the header
-                               // and there attached behaviors are asked.
-                               final HtmlHeaderContainer finalHeader = header;
-                               visitChildren(new IVisitor()
+                               public Object component(Component component)
                                {
-                                       /**
-                                        * @see 
org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component)
-                                        */
-                                       public Object component(Component 
component)
+                                       if (component instanceof 
HtmlHeaderContainer)
                                        {
-                                               
component.renderHead(finalHeader);
-                                               return CONTINUE_TRAVERSAL;
+                                               return component;
                                        }
-                               });
-                               response.close();
+                                       return 
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
+                               }
+                       });
+                       if (header == null)
+                       {
+                               // the markup must at least contain a <body> 
tag for wicket to automatically
+                               // create a HtmlHeaderContainer. Log an error 
if no header container
+                               // was created but any of the components or 
behavior want to contribute
+                               // something to the header.
+                               header = new 
HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
+                               add(header);
+
+                               Response orgResponse = 
getRequestCycle().getResponse();
+                               try
+                               {
+                                       final StringResponse response = new 
StringResponse();
+                                       getRequestCycle().setResponse(response);
 
-                               if (response.getBuffer().length() > 0)
+                                       // Render all header sections of all 
components on the page
+                                       renderHead(header);
+
+                                       // Make sure all Components interested 
in contributing to the header
+                                       // and there attached behaviors are 
asked.
+                                       final HtmlHeaderContainer finalHeader = 
header;
+                                       visitChildren(new IVisitor()
+                                       {
+                                               /**
+                                                * @see 
org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component)
+                                                */
+                                               public Object 
component(Component component)
+                                               {
+                                                       
component.renderHead(finalHeader);
+                                                       return 
CONTINUE_TRAVERSAL;
+                                               }
+                                       });
+                                       response.close();
+
+                                       if (response.getBuffer().length() > 0)
+                                       {
+                                               // @TODO it is not yet working 
properly. JDo to fix it
+                                               
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
+                                               log.error("You probably forgot 
to add a <body> or <header> tag to your markup since no Header Container was 
\n" +
+                                                       "found but components 
where found which want to write to the <head> section.\n" +
+                                                       response.getBuffer());
+                                               
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
+                                       }
+                               }
+                               catch (Exception e)
                                {
-                                       // @TODO it is not yet working 
properly. JDo to fix it
-// 
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
-// log.error("You probably forgot to add a <body> tag to your markup since no 
Header Container was
-// \n" +
-// "found but components where found which want to write to the <head> 
section.\n" +
-// response.getBuffer());
-// 
log.error("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
+                                       // just swallow this exception, there 
isn't much we can do about.
+                                       log.error("header/body check throws 
exception", e);
+                               }
+                               finally
+                               {
+                                       this.remove(header);
+                                       
getRequestCycle().setResponse(orgResponse);
                                }
-                       }
-                       finally
-                       {
-                               this.remove(header);
-                               getRequestCycle().setResponse(orgResponse);
                        }
                }
-
-               super.onDetach();
        }
 }


Reply via email to