You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by al...@apache.org on 2007/05/13 17:20:23 UTC
svn commit: r537597 - in
/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket:
protocol/http/request/WebRequestCodingStrategy.java
request/RequestParameters.java
Author: almaw
Date: Sun May 13 08:20:22 2007
New Revision: 537597
URL: http://svn.apache.org/viewvc?view=rev&rev=537597
Log:
Fix AJAX requests properly by adding a URL depth.
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/RequestParameters.java
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java?view=diff&rev=537597&r1=537596&r2=537597
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java Sun May 13 08:20:22 2007
@@ -40,6 +40,7 @@
import org.apache.wicket.Session;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.protocol.http.UnitTestSettings;
+import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.request.IRequestCodingStrategy;
import org.apache.wicket.request.IRequestTargetMountsInfo;
import org.apache.wicket.request.RequestParameters;
@@ -225,22 +226,17 @@
// First check to see whether the target is mounted
CharSequence url = pathForTarget(requestTarget);
- boolean makePathRelative = false;
-
if (url != null)
{
// Do nothing - we've found the URL and it's mounted.
- makePathRelative = true;
}
else if (requestTarget instanceof IBookmarkablePageRequestTarget)
{
url = encode(requestCycle, (IBookmarkablePageRequestTarget)requestTarget);
- makePathRelative = true;
}
else if (requestTarget instanceof ISharedResourceRequestTarget)
{
url = encode(requestCycle, (ISharedResourceRequestTarget)requestTarget);
- makePathRelative = true;
}
else if (requestTarget instanceof IListenerInterfaceRequestTarget)
{
@@ -252,8 +248,7 @@
// the function we're in again. We therefore need to jump out here
// and return the url immediately, otherwise we end up prefixing it
// with relative path or absolute prefixes twice.
- url = encode(requestCycle, (IPageRequestTarget)requestTarget);
- return url;
+ return encode(requestCycle, (IPageRequestTarget)requestTarget);
}
// fallthough for non-default request targets
else
@@ -263,18 +258,32 @@
if (url != null)
{
- // Add the actual URL. This will be relative to the Wicket Servlet/Filter, with no leading '/'.
+ // Add the actual URL. This will be relative to the Wicket
+ // Servlet/Filter, with no leading '/'.
PrependingStringBuffer prepender = new PrependingStringBuffer(url.toString());
-
- if (makePathRelative)
+
+ // For AJAX requests, we need to make the URLs relative to the
+ // original page.
+ if (requestCycle.getRequest() instanceof WebRequest
+ && ((WebRequest)requestCycle.getRequest()).isAjax())
{
- // Prepend prefix to the URL to make it relative to the current request.
+ for (int i = 0; i < requestCycle.getRequest().getRequestParameters().getUrlDepth(); i++)
+ {
+ prepender.prepend("../");
+ }
+ }
+ else
+ {
+ // Prepend prefix to the URL to make it relative to the current
+ // request.
prepender.prepend(requestCycle.getRequest().getRelativePathPrefixToWicketHandler());
}
-
+
String result = prepender.toString();
- // We need to special-case links to the home page if we're at the same level.
- if (result.length() == 0) {
+ // We need to special-case links to the home page if we're at the
+ // same level.
+ if (result.length() == 0)
+ {
result = "./";
}
return requestCycle.getOriginalResponse().encodeURL(result);
@@ -489,18 +498,24 @@
? PageMap.DEFAULT_NAME
: pageMapName);
+ // Extract URL depth after last colon
+ final String urlDepthString = pathComponents[pathComponents.length - 1];
+ final int urlDepth = Strings.isEmpty(urlDepthString) ? 0 : Integer
+ .parseInt(urlDepthString);
+ parameters.setUrlDepth(urlDepth);
+
// Extract behaviour ID after last colon
- final String behaviourId = pathComponents[pathComponents.length - 1];
+ final String behaviourId = pathComponents[pathComponents.length - 2];
parameters.setBehaviorId(behaviourId.length() != 0 ? behaviourId : null);
// Extract interface name after second-to-last colon
- final String interfaceName = pathComponents[pathComponents.length - 2];
+ final String interfaceName = pathComponents[pathComponents.length - 3];
parameters.setInterfaceName(interfaceName.length() != 0
? interfaceName
: IRedirectListener.INTERFACE.getName());
// Extract version
- final String versionNumberString = pathComponents[pathComponents.length - 3];
+ final String versionNumberString = pathComponents[pathComponents.length - 4];
final int versionNumber = Strings.isEmpty(versionNumberString) ? 0 : Integer
.parseInt(versionNumberString);
parameters.setVersionNumber(versionNumber);
@@ -508,7 +523,7 @@
// Component path is everything after pageMapName and before version
final int start = pageMapName.length() + 1;
final int end = requestString.length() - behaviourId.length() - interfaceName.length()
- - versionNumberString.length() - 3;
+ - versionNumberString.length() - urlDepthString.length() - 4;
final String componentPath = requestString.substring(start, end);
parameters.setComponentPath(componentPath);
}
@@ -783,6 +798,14 @@
{
url.append(params.getBehaviorId());
}
+ url.append(Component.PATH_SEPARATOR);
+
+ // Add URL depth
+ if (params != null && params.getUrlDepth() != 0)
+ {
+ url.append(params.getUrlDepth());
+ }
+
return url;
}
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/RequestParameters.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/RequestParameters.java?view=diff&rev=537597&r1=537596&r2=537597
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/RequestParameters.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/RequestParameters.java Sun May 13 08:20:22 2007
@@ -81,6 +81,9 @@
/** the path info. */
private String path;
+
+ /** depth of the page for relative URLs. */
+ private int urlDepth;
/**
* Construct.
@@ -333,6 +336,26 @@
{
this.versionNumber = versionNumber;
}
+
+ /**
+ * Gets the depth for relative URLs. Used in AJAX requests.
+ *
+ * @return depth (number of slashes)
+ */
+ public int getUrlDepth()
+ {
+ return urlDepth;
+ }
+
+ /**
+ * Sets the depth for relative URLs. Used in AJAX requests.
+ *
+ * @param urlDepth Number of slashes deep the page is that an AJAX request is made from.
+ */
+ public void setUrlDepth(int urlDepth)
+ {
+ this.urlDepth = urlDepth;
+ }
/**
* @see java.lang.Object#toString()
@@ -402,4 +425,5 @@
b.append("]");
return b.toString();
}
+
}