You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2017/04/07 20:29:34 UTC

wicket git commit: WICKET-6349 Stateless form does not work when RecreateBookmarkablePagesAfterExpiry is false

Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x c3e475e2e -> 05b8e6863


WICKET-6349 Stateless form does not work when RecreateBookmarkablePagesAfterExpiry is false


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/05b8e686
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/05b8e686
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/05b8e686

Branch: refs/heads/wicket-7.x
Commit: 05b8e686324651ba5f908331f10c2f7e1737ab97
Parents: c3e475e
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Apr 7 22:28:51 2017 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Apr 7 22:28:51 2017 +0200

----------------------------------------------------------------------
 .../mapper/AbstractBookmarkableMapper.java      |  3 +-
 ...telessAjaxFallbackLinkDoNotRecreatePage.html | 17 ++++
 ...telessAjaxFallbackLinkDoNotRecreatePage.java | 94 ++++++++++++++++++++
 ...telessAjaxFallbackLinkDoNotRecreateTest.java | 50 +++++++++++
 .../html/StatelessAjaxFallbackLinkTest.java     | 20 +----
 5 files changed, 166 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/05b8e686/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java
index 655af8b..b9d5953 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java
@@ -31,7 +31,6 @@ import org.apache.wicket.protocol.http.PageExpiredException;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.request.IRequestHandler;
 import org.apache.wicket.request.IRequestHandlerDelegate;
-import org.apache.wicket.request.IRequestMapper;
 import org.apache.wicket.request.Request;
 import org.apache.wicket.request.Url;
 import org.apache.wicket.request.component.IRequestablePage;
@@ -333,7 +332,7 @@ public abstract class AbstractBookmarkableMapper extends AbstractComponentMapper
 
 	private void checkExpiration(PageProvider provider, PageInfo pageInfo)
 	{
-		if (provider.isNewPageInstance() && !getRecreateMountedPagesAfterExpiry())
+		if (provider.getPageId() != null && provider.isNewPageInstance() && !getRecreateMountedPagesAfterExpiry())
 		{
 			throw new PageExpiredException(String.format("Bookmarkable page with id '%d' has expired.",
 			                                             pageInfo.getPageId()));

http://git-wip-us.apache.org/repos/asf/wicket/blob/05b8e686/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html
new file mode 100644
index 0000000..5020532
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.html
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+    <head>
+     <title>Stateless Wicket</title>
+     <link rel="stylesheet" type="text/css" href="style.css"/>
+    </head>
+    <body>
+        <h2>Stateless ajax fallback link</h2>
+        <div>This link uses ajax when it is available, and a regular
+            wicket roundtrip when ajax or javascript are not available and the
+            page should be stateless.</div>
+
+        <b>Counter: </b>
+        <span id="c2" wicket:id="incrementLabel"></span>
+        <a href="#" id="c2-link" wicket:id="incrementLink">increment</a>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/05b8e686/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java
new file mode 100644
index 0000000..226a89a
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreatePage.java
@@ -0,0 +1,94 @@
+/*
+ * 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.ajax.markup.html;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.util.string.StringValue;
+
+public class StatelessAjaxFallbackLinkDoNotRecreatePage extends WebPage
+{
+  private static final long serialVersionUID = 1L;
+
+  private static final String COUNTER_PARAM = "counter";
+
+  /**
+   * Constructor that is invoked when page is invoked without a session.
+   *
+   * @param parameters
+   *          Page parameters
+   */
+  public StatelessAjaxFallbackLinkDoNotRecreatePage(final PageParameters parameters)
+  {
+    super(parameters);
+    setStatelessHint(true);
+
+    final Label incrementLabel = new Label("incrementLabel", new AbstractReadOnlyModel<Integer>()
+    {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public Integer getObject()
+      {
+        final String counter = getParameter(parameters, COUNTER_PARAM);
+        return counter != null ? Integer.parseInt(counter) : 0;
+      }
+    });
+    final Link<?> incrementLink = new AjaxFallbackLink<Void>("incrementLink")
+    {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public void onClick(final AjaxRequestTarget target)
+      {
+        Integer counter = (Integer) incrementLabel.getDefaultModelObject();
+        updateParams(getPageParameters(), counter);
+        target.add(incrementLabel, this);
+      }
+
+      @Override
+      protected boolean getStatelessHint()
+      {
+        return true;
+      }
+    };
+
+    add(incrementLink);
+    add(incrementLabel.setOutputMarkupId(true));
+  }
+
+  private String getParameter(final PageParameters parameters, final String key)
+  {
+    final StringValue value = parameters.get(key);
+
+    if (value.isNull() || value.isEmpty())
+    {
+      return null;
+    }
+
+    return value.toString();
+  }
+
+  protected final void updateParams(final PageParameters pageParameters, final int counter)
+  {
+    pageParameters.set(COUNTER_PARAM, Integer.toString(counter + 1));
+  }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/05b8e686/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java
new file mode 100644
index 0000000..bc087fc
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkDoNotRecreateTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.ajax.markup.html;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.Session;
+import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.After;
+import org.junit.Test;
+
+public class StatelessAjaxFallbackLinkDoNotRecreateTest extends WicketTestCase
+{
+	@After
+	public void after()
+	{
+		// things must stay stateless
+		assertTrue(Session.get().isTemporary());
+	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-6349
+	 */
+	@Test
+	public void statelessPagesAreAlwaysRecreated()
+	{
+		tester.getApplication().getPageSettings().setRecreateBookmarkablePagesAfterExpiry(false);
+		tester.startPage(StatelessAjaxFallbackLinkDoNotRecreatePage.class);
+
+		final Page page = tester.getLastRenderedPage();
+		assertTrue(page.isStateless());
+
+		tester.clickLink("incrementLink");
+
+		tester.assertRenderedPage(StatelessAjaxFallbackLinkDoNotRecreatePage.class);
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/05b8e686/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkTest.java
index 5cf7ff2..60bd957 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/StatelessAjaxFallbackLinkTest.java
@@ -16,30 +16,18 @@
  */
 package org.apache.wicket.ajax.markup.html;
 
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
 import org.apache.wicket.Session;
 import org.apache.wicket.ajax.AjaxEventBehavior;
 import org.apache.wicket.ajax.StatelessPage;
 import org.apache.wicket.behavior.Behavior;
-import org.apache.wicket.mock.MockApplication;
-import org.apache.wicket.util.tester.WicketTester;
+import org.apache.wicket.util.tester.WicketTestCase;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
-public class StatelessAjaxFallbackLinkTest
-{
-	protected WicketTester tester;
-
-	@Before
-	public void setUp()
-	{
-		tester = new WicketTester(new MockApplication());
-	}
+import java.util.List;
 
+public class StatelessAjaxFallbackLinkTest extends WicketTestCase
+{
 	@After
 	public void teardown()
 	{