You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/12/07 16:05:33 UTC
wicket git commit: WICKET-6578 ResourceLink is stateless
Repository: wicket
Updated Branches:
refs/heads/wicket-8.x a44613885 -> 826f1c9a4
WICKET-6578 ResourceLink is stateless
when used with resourceReference
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/826f1c9a
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/826f1c9a
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/826f1c9a
Branch: refs/heads/wicket-8.x
Commit: 826f1c9a4e03b8458121511ef8a08d97eeb28e5f
Parents: a446138
Author: Sven Meier <sv...@apache.org>
Authored: Fri Dec 7 16:55:41 2018 +0100
Committer: Sven Meier <sv...@apache.org>
Committed: Fri Dec 7 16:55:41 2018 +0100
----------------------------------------------------------------------
.../wicket/markup/html/link/ResourceLink.java | 29 ++++++---
.../markup/html/link/PageWithResourceLink.html | 8 +++
.../markup/html/link/PageWithResourceLink.java | 47 ++++++++++++++
.../markup/html/link/ResourceLinkTest.java | 65 ++++++++++++++++++++
4 files changed, 142 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/826f1c9a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ResourceLink.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ResourceLink.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ResourceLink.java
index dcfe7a5..303c067 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ResourceLink.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ResourceLink.java
@@ -106,15 +106,20 @@ public class ResourceLink<T> extends Link<T> implements IRequestListener
return false;
}
+ /**
+ * For {@link ResourceReference}s this link is stateless.
+ *
+ * @return <code>true</code> if a resourceReference was provided to the
+ * constructor
+ *
+ * @see ResourceLink#ResourceLink(String, ResourceReference)
+ * @see ResourceLink#ResourceLink(String, ResourceReference, PageParameters)
+ */
@Override
- public final void onRequest()
+ protected boolean getStatelessHint()
{
- Attributes a = new Attributes(RequestCycle.get().getRequest(), RequestCycle.get()
- .getResponse(), null);
- resource.respond(a);
-
- super.onRequest();
- }
+ return resourceReference != null;
+ }
@Override
protected final CharSequence getURL()
@@ -140,4 +145,14 @@ public class ResourceLink<T> extends Link<T> implements IRequestListener
}
return urlForListener(resourceParameters);
}
+
+ @Override
+ public final void onRequest()
+ {
+ Attributes a = new Attributes(RequestCycle.get().getRequest(), RequestCycle.get()
+ .getResponse(), null);
+ resource.respond(a);
+
+ super.onRequest();
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/826f1c9a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.html
new file mode 100644
index 0000000..cb27a2c
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.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/826f1c9a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.java
new file mode 100644
index 0000000..ccec067
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/PageWithResourceLink.java
@@ -0,0 +1,47 @@
+/*
+ * 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.Component;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.panel.EmptyPanel;
+import org.apache.wicket.request.resource.IResource;
+import org.apache.wicket.request.resource.ResourceReference;
+
+public class PageWithResourceLink extends WebPage
+{
+ public PageWithResourceLink()
+ {
+ this(new EmptyPanel("link"));
+ }
+
+ public PageWithResourceLink(ResourceReference reference)
+ {
+ this(new ResourceLink<Void>("link", reference));
+ }
+
+ public PageWithResourceLink(IResource resource)
+ {
+ this(new ResourceLink<Void>("link", resource));
+ }
+
+ private PageWithResourceLink(Component component) {
+ add(component);
+
+ setStatelessHint(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/826f1c9a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/ResourceLinkTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/link/ResourceLinkTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/ResourceLinkTest.java
new file mode 100644
index 0000000..78a2a10
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/link/ResourceLinkTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.request.resource.CharSequenceResource;
+import org.apache.wicket.request.resource.IResource;
+import org.apache.wicket.request.resource.ResourceReference;
+import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.Test;
+
+
+/**
+ * Tests {@link ResourceLink}
+ */
+public class ResourceLinkTest extends WicketTestCase
+{
+
+ IResource resource = new CharSequenceResource("text", "DATA");
+
+ /**
+ * Test resource
+ */
+ @Test
+ public void reference()
+ {
+ ResourceReference reference = new ResourceReference(ResourceLinkTest.class, "resource") {
+ @Override
+ public IResource getResource() {
+ return resource;
+ }
+ };
+ PageWithResourceLink page = new PageWithResourceLink(reference);
+
+ tester.startPage(page);
+
+ assertTrue(page.isPageStateless());
+ }
+
+ /**
+ * Test resource
+ */
+ @Test
+ public void resource()
+ {
+ PageWithResourceLink page = new PageWithResourceLink(resource);
+
+ tester.startPage(page);
+
+ assertFalse(page.isPageStateless());
+ }
+}