Author: frankbille
Date: Sun Jan 14 01:30:50 2007
New Revision: 496047

URL: http://svn.apache.org/viewvc?view=rev&rev=496047
Log:
WICKET-208: Fixing AjaxTimerBehaviorTest. It looks ok. The rendered outputs in 
both an AJAX and NOT-AJAX situation looks fine (escaping of " is correct). JBQ, 
please use Java1.4 in any wicket1.x projects which requires this 
(String.replace(String, String) doesn't exist in 1.4)

Modified:
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/AbstractAjaxTimerBehavior.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/AjaxTimerBehaviorTest.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/AbstractAjaxTimerBehavior.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/AbstractAjaxTimerBehavior.java?view=diff&rev=496047&r1=496046&r2=496047
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/AbstractAjaxTimerBehavior.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/AbstractAjaxTimerBehavior.java
 Sun Jan 14 01:30:50 2007
@@ -16,6 +16,7 @@
  */
 package wicket.ajax;
 
+import wicket.RequestCycle;
 import wicket.markup.html.IHeaderResponse;
 import wicket.markup.html.WebPage;
 import wicket.util.time.Duration;
@@ -66,8 +67,14 @@
                if (this.attachedBodyOnLoadModifier == false)
                {
                        this.attachedBodyOnLoadModifier = true;
-                       
((WebPage)getComponent().getPage()).getBodyContainer().addOnLoadModifier(
-                                       getJsTimeoutCall(updateInterval), 
getComponent());
+                       if (RequestCycle.get().getRequestTarget() instanceof 
AjaxRequestTarget) {
+                               
response.renderJavascript(getJsTimeoutCall(updateInterval), 
getComponent().getMarkupId());
+                       }
+                       else
+                       {
+                               
((WebPage)getComponent().getPage()).getBodyContainer().addOnLoadModifier(
+                                               
getJsTimeoutCall(updateInterval), getComponent());
+                       }
                }
        }
 
@@ -78,7 +85,8 @@
         */
        protected final String getJsTimeoutCall(final Duration updateInterval)
        {
-               return "setTimeout(function() { " + getCallbackScript(false, 
true) + " }, "
+               // this might look strange, but it is necessary for IE not to 
leak :(
+               return "setTimeout(\"" + getCallbackScript(false, true) + "\", "
                                + updateInterval.getMilliseconds() + ");";
        }
 
@@ -92,11 +100,7 @@
 
                if (!stopped)
                {
-                       // this might look strange, but it is necessary for IE 
not to leak
-                       String js = "setTimeout(\"" + getCallbackScript(false, 
true) + "\", "
-                                       + updateInterval.getMilliseconds() + 
");";
-
-                       target.appendJavascript(js);
+                       
target.appendJavascript(getJsTimeoutCall(updateInterval));
                }
        }
 

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/AjaxTimerBehaviorTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/AjaxTimerBehaviorTest.java?view=diff&rev=496047&r1=496046&r2=496047
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/AjaxTimerBehaviorTest.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/AjaxTimerBehaviorTest.java
 Sun Jan 14 01:30:50 2007
@@ -31,6 +31,7 @@
 import wicket.markup.html.WebMarkupContainer;
 import wicket.markup.html.basic.Label;
 import wicket.protocol.http.WebRequestCycle;
+import wicket.util.string.Strings;
 import wicket.util.tester.ITestPageSource;
 import wicket.util.time.Duration;
 
@@ -94,9 +95,9 @@
                        }
                });
 
-               application.clickLink(MockPageWithLinkAndComponent.LINK_ID);
-
-               validate(timer);
+               application.clickLink(MockPageWithLinkAndComponent.LINK_ID);
+
+               validate(timer, false);
 
        }
 
@@ -123,8 +124,8 @@
                                return page;
                        }
                });
-
-               validate(timer);
+
+               validate(timer, true);
 
        }
 
@@ -132,15 +133,24 @@
         * Validates the reponse, then makes sure the timer injects itself again
         * when called.
         * 
-        * @param timer
+        * @param timer
+        * @param inBodyOnLoad 
         */
-       private void validate(MyAjaxSelfUpdatingTimerBehavior timer)
+       private void validate(MyAjaxSelfUpdatingTimerBehavior timer, boolean 
inBodyOnLoad)
        {
                String document = 
application.getServletResponse().getDocument();
 
-               String updateScript = timer.getUpdateScript();
+               String updateScript = timer.getUpdateScript();
+               String bodyOnLoadUpdateScript = "<body onload=\"" + 
Strings.replaceAll(updateScript, "\"", "\\\"")+ "\">";
 
-               validateTimerScript(document, updateScript);
+               if (inBodyOnLoad) 
+               {
+                       validateTimerScript(document, bodyOnLoadUpdateScript);
+               }
+               else 
+               {
+                       validateTimerScript(document, updateScript);
+               }
 
 
                application.setupRequestAndResponse();
@@ -164,8 +174,10 @@
         *            the timer script
         */
        private void validateTimerScript(String document, String updateScript)
-       {
-               String quotedRegex = quote(updateScript);
+       {
+               log.debug(document);
+               String quotedRegex;
+               quotedRegex = quote(updateScript);
                Pattern pat = Pattern.compile(quotedRegex, Pattern.DOTALL);
                Matcher mat = pat.matcher(document);
 

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html?view=diff&rev=496047&r1=496046&r2=496047
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html
 Sun Jan 14 01:30:50 2007
@@ -9,7 +9,7 @@
 <script type="text/javascript" 
src="/WicketTester/WicketTester/resources/wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug-drag.js"></script>
 <script type="text/javascript" 
src="/WicketTester/WicketTester/resources/wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug.js"></script>
 </head>
-<body onload="setTimeout(function() { var 
wcall=wicketAjaxGet('/WicketTester/WicketTester?wicket:interface=:0:testPanel:baseSpan:linja1:-1:IUnversionedBehaviorListener&wicket:behaviorId=0&wicket:ignoreIfNotActive=true',
 function() { }, function() { }); }, 2000);">
+<body onload="setTimeout(\"var 
wcall=wicketAjaxGet('/WicketTester/WicketTester?wicket:interface=:0:testPanel:baseSpan:linja1:-1:IUnversionedBehaviorListener&wicket:behaviorId=0&wicket:ignoreIfNotActive=true',
 function() { }, function() { });\", 2000);">
   <span wicket:id="testPanel"><wicket:panel>
     <span wicket:id="baseSpan">
       <wicket:child><wicket:extend>


Reply via email to