WICKET-5306 Dynamic and static extra paramaters not evaluated in ajax 
submitting behavior in a multipart form

Use static extra parameters when submitting multipart form


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

Branch: refs/heads/5299-ajax-strategy
Commit: c276f09cc71747c28b17093bc98f6c5a62b5ad85
Parents: 7d22d55
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Wed Aug 7 11:51:24 2013 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Wed Aug 7 11:51:24 2013 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 14 ++++-
 wicket-core/src/test/js/ajax.js                 | 55 ++++++++++++++++----
 2 files changed, 57 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c276f09c/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 b584861..44719fe 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
@@ -803,12 +803,24 @@
                        form.target = iframe.name;
                        var separator = (attrs.u.indexOf("?")>-1 ? "&" : "?");
                        form.action = attrs.u + separator + 
"wicket-ajax=true&wicket-ajax-baseurl=" + Wicket.Form.encode(getAjaxBaseUrl());
+
+                       // add the static extra parameters
+                       if (attrs.ep) {
+                               var extraParametersArray = 
this._asParamArray(attrs.ep);
+                               if (extraParametersArray.length > 0) {
+                                       var extraParametersQueryString = 
jQuery.param(extraParametersArray);
+                                       form.action = form.action + '&' + 
extraParametersQueryString;
+                               }
+                       }
+
+                       // add the dynamic extra parameters
                        if (jQuery.isArray(attrs.dep)) {
                                var dynamicExtraParameters = 
this._calculateDynamicParameters(attrs);
                                if (dynamicExtraParameters) {
                                        form.action = form.action + '&' + 
dynamicExtraParameters;
                                }
                        }
+
                        form.method = "post";
                        form.enctype = "multipart/form-data";
                        form.encoding = "multipart/form-data";
@@ -826,7 +838,7 @@
                                // show the indicator
                                Wicket.DOM.showIncrementally(attrs.i);
                        }
-                       
+
                        //submit the form into the iframe, response will be 
handled by the onload callback
                        form.submit();
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/c276f09c/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 d370de8..b42c5a8 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -990,7 +990,7 @@ jQuery(document).ready(function() {
                 */
                asyncTest('Submit nested form - success scenario.', function () 
{
 
-                       expect(9);
+                       expect(13);
 
                        var attrs = {
                                f:  "innerForm", // the id of the form to submit
@@ -1002,7 +1002,21 @@ jQuery(document).ready(function() {
                                ad: true, // do not allow default behavior
                                bh: [ function(attrs) { ok(true, "Before 
handler executed"); } ],
                                pre: [ function(attrs) {ok(true, "Precondition 
executed"); return true; } ],
-                               bsh: [ function(attrs) { ok(true, "BeforeSend 
handler executed"); } ],
+                               bsh: [ function(attrs) {
+                                       ok(true, "BeforeSend handler executed");
+
+                                       var form = Wicket.$(attrs.f);
+                                       if (form.tagName.toLowerCase() !== 
"form") {
+                                               do {
+                                                       form = form.parentNode;
+                                               } 
while(form.tagName.toLowerCase() !== "form" && form !== document.body);
+                                       }
+                                       var formUrl = form.action;
+                                       ok(formUrl.indexOf('dynamicEPName') > 
-1, "Dynamic extra parameter name is in the request query string");
+                                       ok(formUrl.indexOf('dynamicEPValue') > 
-1, "Dynamic extra parameter value is in the request query string");
+                                       ok(formUrl.indexOf('extraParamName') > 
-1, "Static extra parameter name is in the request query string");
+                                       ok(formUrl.indexOf('extraParamValue') > 
-1, "Static extra parameter value is in the request query string");
+                               } ],
                                ah: [ function(attrs) { ok(true, "After handler 
executed"); } ],
                                sh: [ function(attrs) { ok(true, "Success 
handler executed"); } ],
                                fh: [ function(attrs) { ok(false, "Failure 
handler should not be executed"); } ],
@@ -1011,14 +1025,16 @@ jQuery(document).ready(function() {
                                                ok(true, "Complete handler 
executed");
                                                
equal(attrs.event.isDefaultPrevented(), false, "default behavior is allowed");
                                        }
-                               ]
-                               ,
+                               ],
                                dep: [
                                        function(attrs) {
                                                ok(true, "Dynamic parameters 
are collected in success scenario!");
-                                               return { 'one': 1 };
+                                               return { 'dynamicEPName': 
'dynamicEPValue' };
                                        }
-                               ]
+                               ],
+                               ep: {
+                                       'extraParamName': 'extraParamValue'
+                               }
                        };
 
                        Wicket.Ajax.ajax(attrs);
@@ -1033,7 +1049,7 @@ jQuery(document).ready(function() {
                 */
                asyncTest('Submit nested form - failure scenario.', function () 
{
 
-                       expect(8);
+                       expect(12);
 
                        var attrs = {
                                f:  "innerForm", // the id of the form to submit
@@ -1045,7 +1061,21 @@ jQuery(document).ready(function() {
                                ad: false,
                                bh: [ function(attrs) { ok(true, "Before 
handler executed"); } ],
                                pre: [ function(attrs) {ok(true, "Precondition 
executed"); return true; } ],
-                               bsh: [ function(attrs) { ok(true, "BeforeSend 
handler executed"); } ],
+                               bsh: [ function(attrs) {
+                                       ok(true, "BeforeSend handler executed");
+
+                                       var form = Wicket.$(attrs.f);
+                                       if (form.tagName.toLowerCase() !== 
"form") {
+                                               do {
+                                                       form = form.parentNode;
+                                               } 
while(form.tagName.toLowerCase() !== "form" && form !== document.body);
+                                       }
+                                       var formUrl = form.action;
+                                       ok(formUrl.indexOf('dynamicEPName') > 
-1, "Dynamic extra parameter name is in the request query string");
+                                       ok(formUrl.indexOf('dynamicEPValue') > 
-1, "Dynamic extra parameter value is in the request query string");
+                                       ok(formUrl.indexOf('extraParamName') > 
-1, "Static extra parameter name is in the request query string");
+                                       ok(formUrl.indexOf('extraParamValue') > 
-1, "Static extra parameter value is in the request query string");
+                               } ],
                                ah: [ function(attrs) { ok(true, "After handler 
executed"); } ],
                                sh: [ function(attrs) { ok(false, "Success 
handler should not be executed"); } ],
                                fh: [ function(attrs) { ok(true, "Failure 
handler executed"); start(); } ],
@@ -1057,10 +1087,13 @@ jQuery(document).ready(function() {
                                ],
                                dep: [
                                        function(attrs) {
-                                               ok(true, "Dynamic parameters 
are collected in failure scenario!");
-                                               return { 'one': 1 };
+                                               ok(true, "Dynamic parameters 
are collected in success scenario!");
+                                               return { 'dynamicEPName': 
'dynamicEPValue' };
                                        }
-                               ]
+                               ],
+                               ep: {
+                                       'extraParamName': 'extraParamValue'
+                               }
                        };
 
                        Wicket.Ajax.ajax(attrs);

Reply via email to