You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/08/08 21:36:41 UTC
cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry IRequestCycle.java
hlship 2005/08/08 12:36:41
Modified: . status.xml
framework/src/test/org/apache/tapestry/engine
TestRequestCycle.java
framework/src/java/org/apache/tapestry/listener
ListenerMapSourceImpl.java
ListenerMethodInvokerImpl.java
framework/src/test/org/apache/tapestry/listener
TestListenerMapSource.java
ListenerMethodHolder.java
framework/src/java/org/apache/tapestry/util
DescribedLocation.java
src/documentation/content/xdocs links.ent
src/documentation/content/xdocs/UsersGuide
listenermethods.xml
framework/src/java/org/apache/tapestry/engine
RequestCycle.java
framework/src/java/org/apache/tapestry IRequestCycle.java
Log:
TAPESTRY-537: Allow listener methods to return ILink, to support redirect-after-post
Revision Changes Path
1.193 +1 -0 jakarta-tapestry/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/status.xml,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -r1.192 -r1.193
--- status.xml 8 Aug 2005 17:53:12 -0000 1.192
+++ status.xml 8 Aug 2005 19:36:37 -0000 1.193
@@ -75,6 +75,7 @@
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-354">Component w/o .jwc file not visible</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-533" due-to="Raphael Jean">Generated client-side javascript is wrong when error message or field display name contains single-quote characters or backslashes</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-365">Set the location for a page that has no specification (just a template) to be relative to the application (or library) specification</action>
+ <action type="fix" dev="HLS" fixes-bug="TAPESTRY-537">Allow listener methods to return ILink, to support redirect-after-post</action>
</release>
<release version="4.0-beta-3" date="Jul 22 2005">
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-398" due-to="Jonas Maurus">HiveMind configuration error breaks the useage of the state: binding prefix</action>
1.5 +16 -0 jakarta-tapestry/framework/src/test/org/apache/tapestry/engine/TestRequestCycle.java
Index: TestRequestCycle.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/engine/TestRequestCycle.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestRequestCycle.java 6 Aug 2005 06:58:28 -0000 1.4
+++ TestRequestCycle.java 8 Aug 2005 19:36:37 -0000 1.5
@@ -18,6 +18,7 @@
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.RedirectException;
import org.apache.tapestry.pageload.PageSource;
import org.apache.tapestry.record.PropertyPersistenceStrategySource;
import org.apache.tapestry.request.RequestContext;
@@ -167,4 +168,19 @@
verifyControls();
}
+
+ public void testSendRedirect()
+ {
+ IRequestCycle cycle = new RequestCycle();
+
+ try
+ {
+ cycle.sendRedirect("http://foo/bar");
+ unreachable();
+ }
+ catch (RedirectException ex)
+ {
+ assertEquals("http://foo/bar", ex.getRedirectLocation());
+ }
+ }
}
\ No newline at end of file
1.5 +2 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/listener/ListenerMapSourceImpl.java
Index: ListenerMapSourceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/listener/ListenerMapSourceImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ListenerMapSourceImpl.java 19 Jun 2005 15:00:45 -0000 1.4
+++ ListenerMapSourceImpl.java 8 Aug 2005 19:36:37 -0000 1.5
@@ -26,6 +26,7 @@
import org.apache.hivemind.util.Defense;
import org.apache.tapestry.IPage;
+import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.event.ResetEventListener;
/**
@@ -127,7 +128,7 @@
if (returnType == void.class || returnType == String.class)
return true;
- return IPage.class.isAssignableFrom(returnType);
+ return IPage.class.isAssignableFrom(returnType) || ILink.class.isAssignableFrom(returnType);
}
private Map convertMethodListMapToInvokerMap(Map map)
1.5 +31 -18 jakarta-tapestry/framework/src/java/org/apache/tapestry/listener/ListenerMethodInvokerImpl.java
Index: ListenerMethodInvokerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/listener/ListenerMethodInvokerImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ListenerMethodInvokerImpl.java 19 Jun 2005 15:00:45 -0000 1.4
+++ ListenerMethodInvokerImpl.java 8 Aug 2005 19:36:37 -0000 1.5
@@ -22,6 +22,7 @@
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
+import org.apache.tapestry.engine.ILink;
/**
* Logic for mapping a listener method name to an actual method invocation; this may require a
@@ -147,26 +148,11 @@
for (int i = 0; i < Tapestry.size(listenerParameters); i++)
parameters[cursor++] = listenerParameters[i];
+ Object methodResult = null;
+
try
{
- Object methodResult = invokeTargetMethod(target, listenerMethod, parameters);
-
- // void methods return null
-
- if (methodResult == null)
- return;
-
- // The method scanner, inside ListenerMapSourceImpl,
- // ensures that only methods that return void, String,
- // or assignable to IPage are considered.
-
- if (methodResult instanceof String)
- {
- cycle.activate((String) methodResult);
- return;
- }
-
- cycle.activate((IPage) methodResult);
+ methodResult = invokeTargetMethod(target, listenerMethod, parameters);
}
catch (InvocationTargetException ex)
{
@@ -188,6 +174,33 @@
ex), target, null, ex);
}
+
+ // void methods return null
+
+ if (methodResult == null)
+ return;
+
+ // The method scanner, inside ListenerMapSourceImpl,
+ // ensures that only methods that return void, String,
+ // or assignable to ILink or IPage are considered.
+
+ if (methodResult instanceof String)
+ {
+ cycle.activate((String) methodResult);
+ return;
+ }
+
+ if (methodResult instanceof ILink)
+ {
+ ILink link = (ILink) methodResult;
+
+ String url = link.getAbsoluteURL();
+
+ cycle.sendRedirect(url);
+ return;
+ }
+
+ cycle.activate((IPage) methodResult);
}
/**
1.4 +34 -0 jakarta-tapestry/framework/src/test/org/apache/tapestry/listener/TestListenerMapSource.java
Index: TestListenerMapSource.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/listener/TestListenerMapSource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestListenerMapSource.java 19 Jun 2005 15:00:45 -0000 1.3
+++ TestListenerMapSource.java 8 Aug 2005 19:36:38 -0000 1.4
@@ -20,6 +20,7 @@
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.engine.ILink;
import org.easymock.MockControl;
/**
@@ -73,6 +74,7 @@
attemptReturnType(true, clazz, "returnsBasePage");
attemptReturnType(false, clazz, "returnsObject");
attemptReturnType(false, clazz, "returnsInt");
+ attemptReturnType(true, clazz, "returnsLink");
}
public void testFoundWithParameters()
@@ -174,6 +176,38 @@
verifyControls();
}
+ public void testReturnLink()
+ {
+ ILink link = newLink("http://foo/bar");
+
+ IRequestCycle cycle = newCycle(null);
+
+ cycle.sendRedirect("http://foo/bar");
+
+ ListenerMethodHolder holder = new ListenerMethodHolder(link);
+
+ replayControls();
+
+ ListenerMapSource source = new ListenerMapSourceImpl();
+
+ ListenerMap map = source.getListenerMapForObject(holder);
+
+ map.getListener("returnsLink").actionTriggered(null, cycle);
+
+ verifyControls();
+ }
+
+ private ILink newLink(String absoluteURL)
+ {
+ MockControl control = newControl(ILink.class);
+ ILink link = (ILink) control.getMock();
+
+ link.getAbsoluteURL();
+ control.setReturnValue(absoluteURL);
+
+ return link;
+ }
+
public void testReturnPageInstance()
{
IPage page = (IPage) newMock(IPage.class);
1.4 +13 -0 jakarta-tapestry/framework/src/test/org/apache/tapestry/listener/ListenerMethodHolder.java
Index: ListenerMethodHolder.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/listener/ListenerMethodHolder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ListenerMethodHolder.java 19 Jun 2005 15:00:45 -0000 1.3
+++ ListenerMethodHolder.java 8 Aug 2005 19:36:38 -0000 1.4
@@ -18,6 +18,7 @@
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.html.BasePage;
/**
@@ -34,6 +35,8 @@
private IPage _page;
+ private ILink _link;
+
public ListenerMethodHolder()
{
}
@@ -43,6 +46,11 @@
_pageName = pageName;
}
+ public ListenerMethodHolder(ILink link)
+ {
+ _link = link;
+ }
+
public ListenerMethodHolder(IPage page)
{
_page = page;
@@ -81,6 +89,11 @@
return _page;
}
+ public ILink returnsLink()
+ {
+ return _link;
+ }
+
public String returnsPageName()
{
return _pageName;
1.2 +0 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/util/DescribedLocation.java
Index: DescribedLocation.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/util/DescribedLocation.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DescribedLocation.java 8 Aug 2005 16:12:26 -0000 1.1
+++ DescribedLocation.java 8 Aug 2005 19:36:39 -0000 1.2
@@ -82,7 +82,6 @@
* A DescribedLocation is equal to another only if their resources are equal, and their
* descriptions are equal.
*/
- @Override
public boolean equals(Object other)
{
if (other instanceof DescribedLocation)
1.20 +1 -0 jakarta-tapestry/src/documentation/content/xdocs/links.ent
Index: links.ent
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/links.ent,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- links.ent 2 Jul 2005 22:51:24 -0000 1.19
+++ links.ent 8 Aug 2005 19:36:41 -0000 1.20
@@ -63,6 +63,7 @@
<!ENTITY IForm '<link href="&apiroot;/IForm.html">IForm</link>'>
<!ENTITY IFormComponent '<link href="&apiroot;/form/IFormComponent.html">IFormComponent</link>'>
<!ENTITY IEngineService '<link href="&apiroot;/IEngineService.html">IEngineService</link>'>
+<!ENTITY ILink '<link href="&apiroot;/engine/ILink.html">ILink</link>'>
<!ENTITY INamespace '<link href="&apiroot;/INamespace.html">INamespace</link>'>
<!ENTITY IMarkupWriter '<link href="&apiroot;/IMarkupWriter.html">IMarkupWriter</link>'>
<!ENTITY IMonitor '<link href="&apiroot;/engine/IMonitor.html">IMonitor</link>'>
1.8 +19 -5 jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/listenermethods.xml
Index: listenermethods.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/listenermethods.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- listenermethods.xml 28 Jul 2005 19:12:09 -0000 1.7
+++ listenermethods.xml 8 Aug 2005 19:36:41 -0000 1.8
@@ -64,11 +64,25 @@
link or form components which invoked the listener method).
</p>
-<p>
-This control over the returned page, especially when combined with
-<link href="injection.html#injection.page">page injection</link>, means that you will rarely
-need to access the &IRequestCycle; object.
-</p>
+<dl>
+ <dt>void</dt>
+ <dd>The listener method does not change the active page.</dd>
+
+<dt>java.lang.String</dt>
+<dd>The listener method may return the name of a page to activate (and render the response). Returning
+null does not change the active page.</dd>
+
+<dt>&IPage;</dt>
+<dd>A non-null &IPage; will activate that page instance. The page object may be obtained
+from the request cycle, or via <link href="injection.html#injection.page">page injection</link>.
+</dd>
+
+<dt>&ILink;</dt>
+<dd>
+Returning a non-null &ILink; will send a redirect to the client for the URL associated with the link.
+This is commonly used to perform a <em>redirect-after-post</em>.
+</dd>
+</dl>
</section> <!-- listenermethods.return -->
1.22 +8 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/RequestCycle.java
Index: RequestCycle.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/RequestCycle.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- RequestCycle.java 28 Jul 2005 19:10:40 -0000 1.21
+++ RequestCycle.java 8 Aug 2005 19:36:41 -0000 1.22
@@ -31,6 +31,7 @@
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.RedirectException;
import org.apache.tapestry.RenderRewoundException;
import org.apache.tapestry.StaleLinkException;
import org.apache.tapestry.Tapestry;
@@ -700,4 +701,11 @@
{
return _idAllocator.allocateId(baseId);
}
+
+ /** @since 4.0 */
+ public void sendRedirect(String URL)
+ {
+ throw new RedirectException(URL);
+ }
+
}
\ No newline at end of file
1.19 +10 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/IRequestCycle.java
Index: IRequestCycle.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/IRequestCycle.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- IRequestCycle.java 18 Apr 2005 17:06:42 -0000 1.18
+++ IRequestCycle.java 8 Aug 2005 19:36:41 -0000 1.19
@@ -343,4 +343,14 @@
*/
public String getUniqueId(String baseId);
+
+ /**
+ * Sends a redirect to the client web browser. This is currently a convinience for constructing
+ * and throwing a {@link RedirectException}, but may change in a later release.
+ *
+ * @since 4.0
+ * @throws RedirectException
+ */
+
+ public void sendRedirect(String URL);
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org