Updated Branches: refs/heads/wicket-1.5.x cf33db490 -> f5cae9496
WICKET-4290: take page parameters from page for links on mounted pages Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f5cae949 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f5cae949 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f5cae949 Branch: refs/heads/wicket-1.5.x Commit: f5cae9496a9918d958c034cea18d5ff3f168d7d5 Parents: cf33db4 Author: Emond Papegaaij <[email protected]> Authored: Thu Jan 12 07:54:06 2012 +0100 Committer: Emond Papegaaij <[email protected]> Committed: Thu Jan 12 07:54:06 2012 +0100 ---------------------------------------------------------------------- .../wicket/request/mapper/MountedMapper.java | 2 +- .../markup/html/link/MountedPageLinkTest.java | 54 +++++++++++++++ .../wicket/markup/html/link/PageWithLink.html | 8 ++ .../wicket/markup/html/link/PageWithLink.java | 40 +++++++++++ 4 files changed, 103 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/f5cae949/wicket-core/src/main/java/org/apache/wicket/request/mapper/MountedMapper.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/request/mapper/MountedMapper.java b/wicket-core/src/main/java/org/apache/wicket/request/mapper/MountedMapper.java index 3137b6c..f5271c5 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/mapper/MountedMapper.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/mapper/MountedMapper.java @@ -385,7 +385,7 @@ public class MountedMapper extends AbstractBookmarkableMapper handler.getBehaviorIndex()); PageComponentInfo pageComponentInfo = new PageComponentInfo(pageInfo, componentInfo); UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), - handler.getPageParameters()); + page.getPageParameters()); url = buildUrl(urlInfo); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/f5cae949/wicket-core/src/test/java/org/apache/wicket/markup/html/link/MountedPageLinkTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/MountedPageLinkTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/MountedPageLinkTest.java new file mode 100644 index 0000000..c2f2b10 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/MountedPageLinkTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.wicket.markup.html.link; + +import org.apache.wicket.WicketTestCase; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.junit.Before; +import org.junit.Test; + +public class MountedPageLinkTest extends WicketTestCase +{ + @Before + public void mountPage() + { + tester.getApplication().mountPage("mount/${param}/part2", PageWithLink.class); + } + + @Test + public void testPageParametersInLink() + { + PageWithLink page = tester.startPage(PageWithLink.class, + new PageParameters().add("param", "value")); + Link<?> link = (Link<?>)page.get("link"); + String url = link.getURL().toString(); + assertTrue("URL for link should contain 'mount/value/part2': " + url, url.toString() + .contains("mount/value/part2")); + tester.executeUrl(url); + } + + @Test + public void testLinkOnExpiredPage() + { + PageWithLink page = tester.startPage(PageWithLink.class, + new PageParameters().add("param", "value")); + Link<?> link = (Link<?>)page.get("link"); + String url = link.getURL().toString(); + url = url.replace("part2?0", "part2?3"); + tester.executeUrl(url); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/f5cae949/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.html new file mode 100644 index 0000000..cb27a2c --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.html @@ -0,0 +1,8 @@ +<html xmlns:wicket> +<head> +<title>Mock Page</title> +</head> +<body> +<a href="#" wicket:id="link">Link</a> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/f5cae949/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.java new file mode 100644 index 0000000..4a309fe --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithLink.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.wicket.markup.html.link; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.junit.Assert; + +public class PageWithLink extends WebPage +{ + public PageWithLink(PageParameters parameters) + { + super(parameters); + Assert.assertEquals("value", getPageParameters().get("param").toString()); + add(new Link<Void>("link") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick() + { + Assert.assertEquals("value", getPageParameters().get("param").toString()); + } + }); + } +}
