You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2016/04/20 00:23:00 UTC
wicket git commit: Revert "WICKET-6075 Error page redirection for
Autocomplete field response"
Repository: wicket
Updated Branches:
refs/heads/wicket-7.x 01fa594ca -> d7e57b953
Revert "WICKET-6075 Error page redirection for Autocomplete field response"
This reverts commit 0e94268a21c9d93e8adcc14df51a601fe0c9242b.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d7e57b95
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d7e57b95
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d7e57b95
Branch: refs/heads/wicket-7.x
Commit: d7e57b95360328eb9a47fc24c89deb6864eb25b6
Parents: 01fa594
Author: Andrea Del Bene <ad...@apache.org>
Authored: Wed Apr 20 00:22:32 2016 +0200
Committer: Andrea Del Bene <ad...@apache.org>
Committed: Wed Apr 20 00:22:32 2016 +0200
----------------------------------------------------------------------
.../wicket/ajax/res/js/wicket-ajax-jquery.js | 127 ++++++++-----------
wicket-core/src/test/js/ajax.js | 30 -----
2 files changed, 55 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/d7e57b95/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 18be42e..55e6e61 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
@@ -704,7 +704,6 @@
if (attrs.wr) {
self.processAjaxResponse(data, textStatus, jqXHR, context);
} else {
- self.handleRedirection(jqXHR, context);
self._executeHandlers(attrs.sh, attrs, jqXHR, data, textStatus);
we.publish(topic.AJAX_CALL_SUCCESS, attrs, jqXHR, data, textStatus);
}
@@ -755,68 +754,6 @@
},
/**
- * Method checks for 'Ajax-Location' header, if available, handles redirection to that URL.
- *
- * @param jqXHR {Object} - the jQuery wrapper around XMLHttpRequest
- * @param context {Object} - the request context with the Ajax request attributes and the FunctionExecuter's steps
- *
- * @return boolean - returns 'true' if 'Ajax-Location' header is found redirection is handled, 'false' otherwise.
- */
- handleRedirection : function (jqXHR, context) {
-
- // first try to get the redirect header
- var redirectUrl;
- try {
- redirectUrl = jqXHR.getResponseHeader('Ajax-Location');
- } catch (ignore) { // might happen in older mozilla
- }
-
- // the redirect header was not set, just return
- if (typeof(redirectUrl) === "undefined" || redirectUrl === null || redirectUrl === "") {
- return false;
- }
-
- // In case the page isn't really redirected. For example say the redirect is to an octet-stream.
- // A file download popup will appear but the page in the browser won't change.
- this.success(context);
-
- var rhttp = /^http:\/\//, // checks whether the string starts with http://
- rhttps = /^https:\/\//; // checks whether the string starts with https://
-
- // support/check for non-relative redirectUrl like as provided and needed in a portlet context
- if (redirectUrl.charAt(0) === '/' || rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
- context.isRedirecting = true;
- Wicket.Ajax.redirect(redirectUrl);
- }
- else {
- var urlDepth = 0;
- while (redirectUrl.substring(0, 3) === "../") {
- urlDepth++;
- redirectUrl = redirectUrl.substring(3);
- }
- // Make this a string.
- var calculatedRedirect = window.location.pathname;
- while (urlDepth > -1) {
- urlDepth--;
- var i = calculatedRedirect.lastIndexOf("/");
- if (i > -1) {
- calculatedRedirect = calculatedRedirect.substring(0, i);
- }
- }
- calculatedRedirect += "/" + redirectUrl;
-
- if (Wicket.Browser.isGecko()) {
- // firefox 3 has problem with window.location setting relative url
- calculatedRedirect = window.location.protocol + "//" + window.location.host + calculatedRedirect;
- }
-
- context.isRedirecting = true;
- Wicket.Ajax.redirect(calculatedRedirect);
- }
- return context.isRedirecting;
- },
-
- /**
* Method that processes the <ajax-response> in the context of an XMLHttpRequest.
*
* @param data {XmlDocument} - the <ajax-response> XML document
@@ -828,19 +765,65 @@
if (jqXHR.readyState === 4) {
- if (this.handleRedirection(jqXHR, context)) {
- return; // 'Ajax-Location' header is set - redirected to it
+ // first try to get the redirect header
+ var redirectUrl;
+ try {
+ redirectUrl = jqXHR.getResponseHeader('Ajax-Location');
+ } catch (ignore) { // might happen in older mozilla
}
- // no redirect, just regular response
- if (Wicket.Log.enabled()) {
- var responseAsText = jqXHR.responseText;
- Wicket.Log.info("Received ajax response (" + responseAsText.length + " characters)");
- Wicket.Log.info("\n" + responseAsText);
+ // the redirect header was set, go to new url
+ if (typeof(redirectUrl) !== "undefined" && redirectUrl !== null && redirectUrl !== "") {
+
+ // In case the page isn't really redirected. For example say the redirect is to an octet-stream.
+ // A file download popup will appear but the page in the browser won't change.
+ this.success(context);
+
+ var rhttp = /^http:\/\//, // checks whether the string starts with http://
+ rhttps = /^https:\/\//; // checks whether the string starts with https://
+
+ // support/check for non-relative redirectUrl like as provided and needed in a portlet context
+ if (redirectUrl.charAt(0) === '/' || rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
+ context.isRedirecting = true;
+ Wicket.Ajax.redirect(redirectUrl);
+ }
+ else {
+ var urlDepth = 0;
+ while (redirectUrl.substring(0, 3) === "../") {
+ urlDepth++;
+ redirectUrl = redirectUrl.substring(3);
+ }
+ // Make this a string.
+ var calculatedRedirect = window.location.pathname;
+ while (urlDepth > -1) {
+ urlDepth--;
+ var i = calculatedRedirect.lastIndexOf("/");
+ if (i > -1) {
+ calculatedRedirect = calculatedRedirect.substring(0, i);
+ }
+ }
+ calculatedRedirect += "/" + redirectUrl;
+
+ if (Wicket.Browser.isGecko()) {
+ // firefox 3 has problem with window.location setting relative url
+ calculatedRedirect = window.location.protocol + "//" + window.location.host + calculatedRedirect;
+ }
+
+ context.isRedirecting = true;
+ Wicket.Ajax.redirect(calculatedRedirect);
+ }
}
+ else {
+ // no redirect, just regular response
+ if (Wicket.Log.enabled()) {
+ var responseAsText = jqXHR.responseText;
+ Wicket.Log.info("Received ajax response (" + responseAsText.length + " characters)");
+ Wicket.Log.info("\n" + responseAsText);
+ }
- // invoke the loaded callback with an xml document
- return this.loadedCallback(data, context);
+ // invoke the loaded callback with an xml document
+ return this.loadedCallback(data, context);
+ }
}
},
http://git-wip-us.apache.org/repos/asf/wicket/blob/d7e57b95/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 21c37a8..bdd772f 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1359,36 +1359,6 @@ jQuery(document).ready(function() {
target.off("event1");
});
- asyncTest('Do not hide the indicator if redirecting.', function () {
-
- expect(2);
-
- var oldRedirect = Wicket.Ajax.redirect;
- Wicket.Ajax.redirect = function() {};
-
- var attrs = {
- u: 'data/ajax/redirectAjaxResponse.xml',
- e: 'event1',
- i: 'ajaxIndicator',
- wr: false,
- sh: [function(attrs, jqXHR, data, textStatus) {
- var indicatorEl = Wicket.$(attrs.i);
- equal("1", indicatorEl.getAttribute("showIncrementallyCount"));
- }],
- coh: [function(attrs, jqXHR, textStatus) {
- var indicatorEl = Wicket.$(attrs.i);
- equal("1", indicatorEl.getAttribute("showIncrementallyCount"));
- Wicket.Ajax.redirect = oldRedirect;
- start();
- }]
- };
-
- Wicket.Ajax.ajax(attrs);
- var target = jQuery(window);
- target.triggerHandler("event1");
- target.off("event1");
- });
-
asyncTest('Do hide the indicator if not redirecting.', function () {
expect(2);