You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/03/18 20:28:11 UTC
git commit: TAP5-1659: PageLink: page parameter should accept
page-classes and page-instances
Repository: tapestry-5
Updated Branches:
refs/heads/master 88f6a1922 -> 19b396090
TAP5-1659: PageLink: page parameter should accept page-classes and
page-instances
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/19b39609
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/19b39609
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/19b39609
Branch: refs/heads/master
Commit: 19b3960905197fd5848bc8e0cc8e90379e6ace44
Parents: 88f6a19
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Tue Mar 18 16:27:57 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Tue Mar 18 16:27:57 2014 -0300
----------------------------------------------------------------------
.../tapestry5/corelib/components/PageLink.java | 26 ++++-
.../ActivationContextIntegrationTests.java | 105 +++++++++++++++++++
.../ActivationContextintegrationTests.java | 88 ----------------
.../integration/activationctx/pages/Index.java | 41 +++++++-
.../integration/activationctx/pages/Index.tml | 48 +++++++++
5 files changed, 214 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/19b39609/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 0528f78..5d38d63 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
@@ -36,10 +36,15 @@ import org.apache.tapestry5.services.PageRenderLinkSource;
public class PageLink extends AbstractLink
{
/**
- * The logical name of the page to link to.
+ * The page to link to. If a <code>String</code>, as usual, it should be the page logical name.
+ * If it's a <code>Class</code> instance, it's treated as the target page.
+ * If it's not a <code>String</code> nor an <code>Class</code>, the target page will be
+ * the result of calling <code>page.getClass()</code>.
+ * Notice you'll need to use the <code>prop</code> binding when passing a value which
+ * isn't a <code>String</code>.
*/
@Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
- private String page;
+ private Object page;
/**
* If provided, this is the activation context for the target page (the information will be encoded into the URL).
@@ -55,9 +60,20 @@ public class PageLink extends AbstractLink
{
if (isDisabled()) return;
- Link link = resources.isBound("context")
- ? linkSource.createPageRenderLinkWithContext(page, context == null ? InternalConstants.EMPTY_STRING_ARRAY : context)
- : linkSource.createPageRenderLink(page);
+ Link link;
+ if (page instanceof String) {
+ final String pageName = (String) page;
+ link = resources.isBound("context")
+ ? linkSource.createPageRenderLinkWithContext(pageName, context == null ? InternalConstants.EMPTY_STRING_ARRAY : context)
+ : linkSource.createPageRenderLink(pageName);
+ }
+ else {
+ // If page is a Class, use it directly. If not, use its class (type)
+ Class<?> clasz = page instanceof Class<?> ? (Class<?>) page : page.getClass();
+ link = resources.isBound("context")
+ ? linkSource.createPageRenderLinkWithContext(clasz, context == null ? InternalConstants.EMPTY_STRING_ARRAY : context)
+ : linkSource.createPageRenderLink(clasz);
+ }
writeLink(writer, link);
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/19b39609/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextIntegrationTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextIntegrationTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextIntegrationTests.java
new file mode 100644
index 0000000..9cb4ef7
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextIntegrationTests.java
@@ -0,0 +1,105 @@
+// Copyright 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.activationctx;
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase;
+import org.testng.annotations.Test;
+
+/**
+ * To test TAP5-2070
+ */
+public class ActivationContextIntegrationTests extends TapestryCoreTestCase
+{
+
+ private final static String STRING_PARAMETER = null;
+ private final static String PAGE_CLASS_PARAMETER = "page class";
+ private final static String PAGE_INSTANCE_PARAMETER = "page instance";
+
+ @Test
+ public void no_context_correct()
+ {
+ assertLinksAreCorrect("No context correct", "You are able to see me only without activation context");
+ }
+
+ @Test
+ public void no_context_error()
+ {
+ openLinks("No context error");
+
+ assertTextPresent("HTTP ERROR 404");
+ }
+
+ @Test
+ public void one_context_without()
+ {
+ openLinks("One context without");
+
+ assertTextPresent("HTTP ERROR 404");
+ }
+
+ @Test
+ public void one_context_with_one()
+ {
+ openLinks("One context correct");
+
+ assertTextPresent("You are able to see me only with one parameter in the activation context");
+ }
+
+ @Test
+ public void one_context_with_two()
+ {
+ openLinks("One context error");
+
+ assertTextPresent("HTTP ERROR 404");
+ }
+
+ @Test
+ public void two_context_without()
+ {
+ openLinks("Two context without");
+
+ assertTextPresent("HTTP ERROR 404");
+ }
+
+ @Test
+ public void two_context_with_one()
+ {
+ openLinks("Two context error");
+
+ assertTextPresent("HTTP ERROR 404");
+ }
+
+ @Test
+ public void two_context_with_two()
+ {
+ openLinks("Two context correct");
+
+ assertTextPresent("You are able to see me only with two parameters in the activation context");
+ }
+
+ private void assertLinksAreCorrect(final String suffix, final String expectedText)
+ {
+ assertNoContextCorrect(suffix, STRING_PARAMETER, expectedText);
+ assertNoContextCorrect(suffix, PAGE_CLASS_PARAMETER, expectedText);
+ assertNoContextCorrect(suffix, PAGE_INSTANCE_PARAMETER, expectedText);
+ }
+
+ private void assertNoContextCorrect(String linkSuffix, String linkPrefix, String expectedText)
+ {
+ openLinks("No context correct" + linkPrefix != null ? ": " + linkPrefix : "");
+ assertTextPresent(expectedText);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/19b39609/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextintegrationTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextintegrationTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextintegrationTests.java
deleted file mode 100644
index 2a0d2b5..0000000
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/ActivationContextintegrationTests.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 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.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.tapestry5.integration.activationctx;
-
-import org.apache.tapestry5.integration.TapestryCoreTestCase;
-import org.testng.annotations.Test;
-
-/**
- * To test TAP5-2070
- */
-public class ActivationContextintegrationTests extends TapestryCoreTestCase
-{
- @Test
- public void no_context_correct()
- {
- openLinks("No context correct");
-
- assertTextPresent("You are able to see me only without activation context");
- }
-
- @Test
- public void no_context_error()
- {
- openLinks("No context error");
-
- assertTextPresent("HTTP ERROR 404");
- }
-
- @Test
- public void one_context_without()
- {
- openLinks("One context without");
-
- assertTextPresent("HTTP ERROR 404");
- }
-
- @Test
- public void one_context_with_one()
- {
- openLinks("One context correct");
-
- assertTextPresent("You are able to see me only with one parameter in the activation context");
- }
-
- @Test
- public void one_context_with_two()
- {
- openLinks("One context error");
-
- assertTextPresent("HTTP ERROR 404");
- }
-
- @Test
- public void two_context_without()
- {
- openLinks("Two context without");
-
- assertTextPresent("HTTP ERROR 404");
- }
-
- @Test
- public void two_context_with_one()
- {
- openLinks("Two context error");
-
- assertTextPresent("HTTP ERROR 404");
- }
-
- @Test
- public void two_context_with_two()
- {
- openLinks("Two context correct");
-
- assertTextPresent("You are able to see me only with two parameters in the activation context");
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/19b39609/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/pages/Index.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/pages/Index.java
index b91111c..0def4dd 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/pages/Index.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/pages/Index.java
@@ -14,11 +14,22 @@
package org.apache.tapestry5.integration.activationctx.pages;
+import org.apache.tapestry5.annotations.InjectPage;
+
/**
- * TAP5-2070 Integration test index page
+ * TAP5-2070 and TAP5-1659 Integration test index page
*/
public class Index
{
+
+ @InjectPage
+ private NoContext noContext;
+
+ @InjectPage
+ private OneContext oneContext;
+
+ @InjectPage
+ private TwoContext twoContext;
public String[] getTwoValues()
{
@@ -27,4 +38,32 @@ public class Index
"Two"
};
}
+
+ public Class<?> getNoContextClass() {
+ return NoContext.class;
+ }
+
+ public Class<?> getOneContextClass() {
+ return OneContext.class;
+ }
+
+ public Class<?> getTwoContextClass() {
+ return TwoContext.class;
+ }
+
+ public NoContext getNoContext()
+ {
+ return noContext;
+ }
+
+ public OneContext getOneContext()
+ {
+ return oneContext;
+ }
+
+ public TwoContext getTwoContext()
+ {
+ return twoContext;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/19b39609/tapestry-core/src/test/resources/org/apache/tapestry5/integration/activationctx/pages/Index.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/activationctx/pages/Index.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/activationctx/pages/Index.tml
index d6fc3f7..e7c836e 100644
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/activationctx/pages/Index.tml
+++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/activationctx/pages/Index.tml
@@ -4,36 +4,84 @@
<li>
<t:pagelink page="nocontext">No context correct</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:noContextClass">No context correct: page class</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:noContext">No context correct: page instance</t:pagelink>
+ </li>
<li>
<t:pagelink page="nocontext" context="literal:one">No context error</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:noContextClass" context="literal:one">No context error: page class</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:noContextClass" context="literal:one">No context error: page instance</t:pagelink>
+ </li>
<li>
<t:pagelink page="onecontext">One context without</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:oneContext">One context without: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:oneContextClass">One context without: page class</t:pagelink>
+ </li>
<li>
<t:pagelink page="onecontext" context="literal:one">One context correct</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:oneContext" context="literal:one">One context correct: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:oneContextClass" context="literal:one">One context correct: page class</t:pagelink>
+ </li>
<li>
<t:pagelink page="onecontext" context="twoValues">One context error</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:oneContext" context="twoValues">One context error: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:oneContextClass" context="twoValues">One context error: page class</t:pagelink>
+ </li>
<li>
<t:pagelink page="twocontext">Two context without</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:twoContext">Two context without: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:twoContextClass">Two context without: page class</t:pagelink>
+ </li>
<li>
<t:pagelink page="twocontext" context="literal:one">Two context error</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:twoContext" context="literal:one">Two context error: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:twoContextClass" context="literal:one">Two context error: page class</t:pagelink>
+ </li>
<li>
<t:pagelink page="twocontext" context="twoValues">Two context correct</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="prop:twoContext" context="twoValues">Two context correct: page instance</t:pagelink>
+ </li>
+ <li>
+ <t:pagelink page="prop:twoContextClass" context="twoValues">Two context correct: page class</t:pagelink>
+ </li>
</ul>
</t:layout>
\ No newline at end of file