You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/06/04 20:59:21 UTC
[4/4] git commit: TAP5-2063: Repair conflict between multi-valued
parameters in Links, and parameters via @ActivationRequestParameter
TAP5-2063: Repair conflict between multi-valued parameters in Links, and parameters via @ActivationRequestParameter
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/7f5767b7
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/7f5767b7
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/7f5767b7
Branch: refs/heads/master
Commit: 7f5767b774b0483206be8abc43a981bb44572c11
Parents: 37adb4e
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jun 4 11:59:12 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jun 4 11:59:12 2013 -0700
----------------------------------------------------------------------
.../tapestry5/corelib/base/AbstractLink.java | 13 +++-
.../tapestry5/corelib/components/ActionLink.java | 7 +--
.../tapestry5/corelib/components/EventLink.java | 6 +--
.../tapestry5/corelib/components/PageLink.java | 17 +++--
.../corelib/components/PageLinkTest.groovy | 54 +++++++++++++++
5 files changed, 76 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7f5767b7/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractLink.java
index fc44a90..8f0d69c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractLink.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2011 The Apache Software Foundation
+// Copyright 2007-2013The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public abstract class AbstractLink implements ClientElement
private Map<String, ?> parameters;
@Inject
- private ComponentResources resources;
+ protected ComponentResources resources;
@Inject
private JavaScriptSupport jsSupport;
@@ -116,7 +116,14 @@ public abstract class AbstractLink implements ClientElement
for(Map.Entry<String,?> entry : parameters.entrySet())
{
- link.addParameterValue(entry.getKey(), entry.getValue());
+ String name = entry.getKey();
+
+ // Per TAP5-2126, we want to override any prior value (typically, set from an ActivationRequestParameter)
+ // with the new value.
+
+ link.removeParameter(name);
+
+ link.addParameterValue(name, entry.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7f5767b7/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ActionLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ActionLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ActionLink.java
index 15d718f..fc6a026 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ActionLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ActionLink.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,12 +14,10 @@
package org.apache.tapestry5.corelib.components;
-import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Events;
import org.apache.tapestry5.corelib.base.AbstractComponentEventLink;
-import org.apache.tapestry5.ioc.annotations.Inject;
/**
* Component that triggers an action on the server with a subsequent full page refresh.
@@ -29,9 +27,6 @@ import org.apache.tapestry5.ioc.annotations.Inject;
@Events(EventConstants.ACTION)
public class ActionLink extends AbstractComponentEventLink
{
- @Inject
- private ComponentResources resources;
-
@Override
protected Link createLink(Object[] contextArray)
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7f5767b7/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/EventLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/EventLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/EventLink.java
index b821f73..8aa3e1a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/EventLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/EventLink.java
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractComponentEventLink;
-import org.apache.tapestry5.ioc.annotations.Inject;
/**
* A close relative of {@link org.apache.tapestry5.corelib.components.ActionLink} except in two ways.
@@ -42,9 +41,6 @@ public class EventLink extends AbstractComponentEventLink
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private String event;
- @Inject
- private ComponentResources resources;
-
String defaultEvent()
{
return resources.getId();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7f5767b7/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PageLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PageLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PageLink.java
index 1b66476..0528f78 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PageLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PageLink.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2011 The Apache Software Foundation
+// Copyright 2007-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,12 +15,13 @@
package org.apache.tapestry5.corelib.components;
import org.apache.tapestry5.BindingConstants;
-import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractLink;
+import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.PageRenderLinkSource;
/**
* Generates a render request link to some other page in the application. If an activation context is supplied (as the
@@ -29,7 +30,7 @@ import org.apache.tapestry5.ioc.annotations.Inject;
* <p/>
* Pages are not required to have an activation context. When a page does have an activation context, the value
* typically represents the identity of some object displayed or otherwise manipulated by the page.
- *
+ *
* @tapestrydoc
*/
public class PageLink extends AbstractLink
@@ -40,9 +41,6 @@ public class PageLink extends AbstractLink
@Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
private String page;
- @Inject
- private ComponentResources resources;
-
/**
* If provided, this is the activation context for the target page (the information will be encoded into the URL).
* If not provided, then the target page will provide its own activation context.
@@ -50,11 +48,16 @@ public class PageLink extends AbstractLink
@Parameter
private Object[] context;
+ @Inject
+ private PageRenderLinkSource linkSource;
+
void beginRender(MarkupWriter writer)
{
if (isDisabled()) return;
- Link link = resources.createPageLink(page, resources.isBound("context"), context);
+ Link link = resources.isBound("context")
+ ? linkSource.createPageRenderLinkWithContext(page, context == null ? InternalConstants.EMPTY_STRING_ARRAY : context)
+ : linkSource.createPageRenderLink(page);
writeLink(writer, link);
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7f5767b7/tapestry-core/src/test/groovy/org/apache/tapestry5/corelib/components/PageLinkTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/corelib/components/PageLinkTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/corelib/components/PageLinkTest.groovy
new file mode 100644
index 0000000..f8e8fe1
--- /dev/null
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/corelib/components/PageLinkTest.groovy
@@ -0,0 +1,54 @@
+package org.apache.tapestry5.corelib.components
+
+import org.apache.tapestry5.ComponentResources
+import org.apache.tapestry5.Link
+import org.apache.tapestry5.MarkupWriter
+import org.apache.tapestry5.services.PageRenderLinkSource
+import org.apache.tapestry5.test.TapestryTestCase
+import org.testng.annotations.Test
+
+
+class PageLinkTest extends TapestryTestCase {
+
+ @Test
+ void parameters_parameter_overrides_ARP() {
+
+ Link link = newMock Link
+ ComponentResources resources = newMock ComponentResources
+ PageRenderLinkSource source = newMock PageRenderLinkSource
+ MarkupWriter writer = newMock MarkupWriter
+
+ expect(resources.isBound("context")).andReturn false
+ expect(source.createPageRenderLink("Target")).andReturn link
+
+ expect(resources.isBound("parameters")).andReturn true
+
+ // TAP5-2126:
+ link.removeParameter("foo")
+
+ expect(link.addParameterValue("foo", "bar")).andReturn link
+
+ expect(link.toURI()).andReturn "/xyz"
+
+ expect(writer.element("a", "href", "/xyz")).andReturn null
+ writer.attributes();
+
+ resources.renderInformalParameters(writer);
+
+ replay()
+
+ PageLink component = new PageLink(
+ resources: resources,
+ page: "Target",
+ linkSource: source)
+
+
+ // Not sure why this is necessary; should be able to set it as with others
+ // above!
+ set component, "parameters", [foo: "bar"]
+
+ component.beginRender writer
+
+ verify()
+ }
+}