Author: ivaynberg
Date: Sat Nov  5 19:40:58 2011
New Revision: 1198035

URL: http://svn.apache.org/viewvc?rev=1198035&view=rev
Log:

Issue: WICKET-4200

Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
    wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=1198035&r1=1198034&r2=1198035&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
 Sat Nov  5 19:40:58 2011
@@ -671,18 +671,20 @@ public class AjaxRequestTarget implement
                // invoke onbeforerespond event on listeners
                fireOnBeforeRespondListeners();
 
-               // normal behavior
+               // process added components
+               respondComponents(bodyResponse);
+
+               fireOnAfterRespondListeners(bodyResponse);
+
+               // queue up prepend javascripts. unlike other steps these are 
executed out of order so that
+               // components can contribute them from inside their 
onbeforerender methods.
                Iterator<CharSequence> it = prependJavaScripts.iterator();
                while (it.hasNext())
                {
                        CharSequence js = it.next();
-                       respondInvocation(bodyResponse, js);
+                       respondPriorityInvocation(bodyResponse, js);
                }
 
-               // process added components
-               respondComponents(bodyResponse);
-
-               fireOnAfterRespondListeners(bodyResponse);
 
                // execute the dom ready javascripts as first javascripts
                // after component replacement
@@ -1284,12 +1286,26 @@ public class AjaxRequestTarget implement
                headerRendering = false;
        }
 
+       private void respondInvocation(final Response response, final 
CharSequence js)
+       {
+               respondJavascriptInvocation("evaluate", response, js);
+       }
+
+       private void respondPriorityInvocation(final Response response, final 
CharSequence js)
+       {
+               respondJavascriptInvocation("priority-evaluate", response, js);
+       }
+
+
        /**
-        * 
+        * @param invocation
+        *            type of invocation tag, usually {@literal evaluate} or
+        *            {@literal priority-evaluate}
         * @param response
         * @param js
         */
-       private void respondInvocation(final Response response, final 
CharSequence js)
+       private void respondJavascriptInvocation(final String invocation, final 
Response response,
+               final CharSequence js)
        {
                boolean encoded = false;
                CharSequence javascript = js;
@@ -1301,7 +1317,8 @@ public class AjaxRequestTarget implement
                        javascript = encode(js);
                }
 
-               response.write("<evaluate");
+               response.write("<");
+               response.write(invocation);
                if (encoded)
                {
                        response.write(" encoding=\"");
@@ -1309,10 +1326,14 @@ public class AjaxRequestTarget implement
                        response.write("\"");
                }
                response.write(">");
+
                response.write("<![CDATA[");
                response.write(javascript);
                response.write("]]>");
-               response.write("</evaluate>");
+
+               response.write("</");
+               response.write(invocation);
+               response.write(">");
 
                encodingBodyResponse.reset();
        }

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js?rev=1198035&r1=1198034&r2=1198035&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js 
(original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js 
Sat Nov  5 19:40:58 2011
@@ -1300,6 +1300,15 @@ Wicket.Ajax.Call.prototype = {
                            }
                        }
                        
+                       // go through the ajax response and execute all 
priority-invocations first
+
+                   for (var i = 0; i < root.childNodes.length; ++i) {
+                       var node = root.childNodes[i];                          
+                       if (node.tagName == "priority-evaluate") {
+                          this.processEvaluation(steps, node);
+                       }
+                   }
+
                        // go through the ajax response and for every action 
(component, js evaluation, header contribution)
                        // ad the proper closure to steps
                        var stepIndexOfLastReplacedComponent = -1;
@@ -1319,7 +1328,6 @@ Wicket.Ajax.Call.prototype = {
                        } else if (node.tagName == "redirect") {
                           this.processRedirect(steps, node);
                        }
-
                    }
                        if (stepIndexOfLastReplacedComponent != -1) {
                                this.processFocusedComponentReplaceCheck(steps, 
stepIndexOfLastReplacedComponent);


Reply via email to