You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/06/26 10:06:38 UTC

git commit: WICKET-4606 dynamic extra parameter gets used/executed even when ajaxcallistener is preconditioned to false

Updated Branches:
  refs/heads/master 884a78dd9 -> 24018e53f


WICKET-4606 dynamic extra parameter gets used/executed even when ajaxcallistener is preconditioned to false

Dynamic extra parameters should be added to settings.url when the method is GET and to settings.data when the method is POST.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/24018e53
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/24018e53
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/24018e53

Branch: refs/heads/master
Commit: 24018e53ff0ab7b7710361abb9468b5d9413956f
Parents: 884a78d
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Jun 26 11:04:16 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Jun 26 11:04:16 2012 +0300

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       |    9 ++-
 wicket-core/src/test/js/ajax.js                    |   45 ++++++++++++++-
 2 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/24018e53/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 5c2b7fa..4bc2102 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -526,8 +526,13 @@
 							params = params.concat(extraParam);
 						}
 						queryString = jQuery.param(params);
-						separator = settings.url.indexOf('?') > -1 ? '&' : '?';
-						settings.url = settings.url + separator + queryString;
+						if (settings.type.toLowerCase() === 'post') {
+							separator = settings.data.length > 0 ? '&' : '';
+							settings.data = settings.data + separator + queryString;
+						} else {
+							separator = settings.url.indexOf('?') > -1 ? '&' : '?';
+							settings.url = settings.url + separator + queryString;
+						}
 					}
 
 					Wicket.Event.publish('/ajax/call/before', attrs, jqXHR, settings);

http://git-wip-us.apache.org/repos/asf/wicket/blob/24018e53/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index 6db63b3..b12ae17 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -62,7 +62,7 @@ jQuery(document).ready(function() {
 	// Ajax tests are executed only when run with Web Server
 	if ( !isLocal ) {
 
-		module('Wicket.Ajax.stateChangeCallback');
+		module('Wicket.Ajax');
 
 		asyncTest('Wicket.Ajax - processEvaluation with mock data.', function () {
 
@@ -621,13 +621,18 @@ jQuery(document).ready(function() {
 			$el.triggerHandler("event1");
 		});
 
-		asyncTest('Wicket.Ajax - verify dynamic parameters are appended to the Ajax call data (GET/POST params).', function () {
+		/**
+		 * When using GET method the parameters should be added to 'settings.url'
+		 * WICKET-4606
+		 */
+		asyncTest('Wicket.Ajax - verify dynamic parameters are appended to the Ajax GET params.', function () {
 
 			expect(5);
 
 			var attrs = {
 				u: 'data/ajax/nonExisting.json',
 				e: 'event1',
+				m: 'get',
 				dt: 'json', // datatype
 				wr: false, // not Wicket's <ajax-response>
 				dep: [ function() {return { "one": 1, "two": 2 } } ]
@@ -646,7 +651,43 @@ jQuery(document).ready(function() {
 			var target = jQuery(window);
 			target.triggerHandler("event1");
 			target.off("event1");
+			jQuery(document).off();
+		});
+
+		/**
+		 * When using POST method the parameters should be added to 'settings.data'
+		 * WICKET-4606
+		 */
+		asyncTest('Wicket.Ajax - verify dynamic parameters are appended to the Ajax POST params.', function () {
+
+			expect(7);
 
+			var attrs = {
+				u: 'data/ajax/nonExisting.json',
+				e: 'event1',
+				m: 'post',
+				ep: [ {name: 'one', value: 'static1'}, {name: 'one', value: 'static2'} ],
+				dt: 'json', // datatype
+				wr: false, // not Wicket's <ajax-response>
+				dep: [ function() {return [ {name: "one", value: 'dynamic1'}, {name: "one", value: 'dynamic2'} ] } ]
+			};
+
+			Wicket.Event.subscribe('/ajax/call/before', function(jqEvent, attributes, jqXHR, settings) {
+				deepEqual(attrs, attributes, 'Before: attrs');
+				ok(jQuery.isFunction(jqXHR.getResponseHeader), 'Before: Assert that jqXHR is a XMLHttpRequest');
+				ok(jQuery.isFunction(settings.beforeSend), 'Before: Assert that settings is the object passed to jQuery.ajax()');
+				ok(settings.data.indexOf('one=static1') > -1, 'Parameter "one" with value "static1" is found');
+				ok(settings.data.indexOf('one=static2') > -1, 'Parameter "one" with value "static2" is found');
+				ok(settings.data.indexOf('one=dynamic1') > -1, 'Parameter "one" with value "dynamic1" is found');
+				ok(settings.data.indexOf('one=dynamic2') > -1, 'Parameter "one" with value "dynamic2" is found');
+				start();
+			});
+
+			Wicket.Ajax.ajax(attrs);
+			var target = jQuery(window);
+			target.triggerHandler("event1");
+			target.off("event1");
+			jQuery(document).off();
 		});
 	}
 });