Author: jcompagner
Date: Wed Oct 31 06:28:59 2007
New Revision: 590662

URL: http://svn.apache.org/viewvc?rev=590662&view=rev
Log:
pages will remember there constructing page parameters and the request cycle 
uses that to generate the stateless links

Added:
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.html
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_indexed_mount_result.html
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_mount_result.html
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_result.html
Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Page.java
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentTest.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Page.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Page.java?rev=590662&r1=590661&r2=590662&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Page.java 
(original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Page.java Wed 
Oct 31 06:28:59 2007
@@ -218,6 +218,9 @@
        /** Version manager for this page */
        private IPageVersionManager versionManager;
 
+       /** The page parameters object hat constructed this page */
+       private PageParameters parameters;
+
        /**
         * Constructor.
         */
@@ -276,7 +279,8 @@
        }
 
        /**
-        * Constructor.
+        * The [EMAIL PROTECTED] PageParameters} parameter will be stored in 
this page and then those parameters
+        * will be used to create stateless links to this bookmarkable page.
         * 
         * @param parameters
         *            externally passed parameters
@@ -285,7 +289,19 @@
        protected Page(final PageParameters parameters)
        {
                super(null);
+               this.parameters = parameters;
                init();
+       }
+
+       /**
+        * The [EMAIL PROTECTED] PageParameters} object that was used to 
construct this page. This will be used in
+        * creating stateless/bookmarkable links to this page
+        * 
+        * @return
+        */
+       public PageParameters getPageParameters()
+       {
+               return parameters;
        }
 
        /**

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?rev=590662&r1=590661&r2=590662&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java 
(original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java 
Wed Oct 31 06:28:59 2007
@@ -824,8 +824,11 @@
                if (listener != IRedirectListener.INTERFACE && 
component.isStateless() &&
                                page.isBookmarkable())
                {
+                       PageParameters pageParameters = 
page.getPageParameters();
+                       if (pageParameters == null)
+                               pageParameters = new PageParameters();
                        target = new 
BookmarkableListenerInterfaceRequestTarget(page.getPageMapName(), page
-                                       .getClass(), new PageParameters(), 
component, listener);
+                                       .getClass(), pageParameters, component, 
listener);
                }
                else
                {

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.html?rev=590662&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.html
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.html
 Wed Oct 31 06:28:59 2007
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a href="#" wicket:id="link">test</a>
+</body>
+</html>
\ No newline at end of file

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java?rev=590662&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java
 Wed Oct 31 06:28:59 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.stateless;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.link.StatelessLink;
+
+/**
+ * @author jcompagner
+ */
+public class StatelessComponentPageWithParams extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * Construct.
+        * 
+        * @param params
+        */
+       public StatelessComponentPageWithParams(PageParameters params)
+       {
+               super(params);
+               add(new StatelessLink("link")
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       public void onClick()
+                       {
+                               if (getPageParameters().size() == 2)
+                               {
+                                       throw new 
WicketRuntimeException("wanted exception");
+                               }
+                       }
+               });
+
+       }
+}

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_indexed_mount_result.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_indexed_mount_result.html?rev=590662&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_indexed_mount_result.html
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_indexed_mount_result.html
 Wed Oct 31 06:28:59 2007
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a 
href="stateless/testValue1/testValue2/wicket:interface/%3A0%3Alink%3A%3AILinkListener%3A%3A/"
 wicket:id="link">test</a>
+</body>
+</html>
\ No newline at end of file

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_mount_result.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_mount_result.html?rev=590662&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_mount_result.html
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_mount_result.html
 Wed Oct 31 06:28:59 2007
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a 
href="stateless/testParam1/testValue1/testParam2/testValue2/wicket:interface/%3A0%3Alink%3A%3AILinkListener%3A%3A/"
 wicket:id="link">test</a>
+</body>
+</html>
\ No newline at end of file

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_result.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_result.html?rev=590662&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_result.html
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams_result.html
 Wed Oct 31 06:28:59 2007
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a 
href="?wicket:bookmarkablePage=%3Aorg.apache.wicket.stateless.StatelessComponentPageWithParams&amp;testParam1=testValue1&amp;testParam2=testValue2&amp;wicket:interface=%3A0%3Alink%3A%3AILinkListener%3A%3A"
 wicket:id="link">test</a>
+</body>
+</html>
\ No newline at end of file

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentTest.java?rev=590662&r1=590661&r2=590662&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentTest.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentTest.java
 Wed Oct 31 06:28:59 2007
@@ -16,7 +16,9 @@
  */
 package org.apache.wicket.stateless;
 
+import org.apache.wicket.PageParameters;
 import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.request.target.coding.IndexedParamUrlCodingStrategy;
 
 /**
  * @author jcompagner
@@ -83,4 +85,91 @@
                }
        }
 
+       /**
+        * @throws Exception
+        */
+       public void testStatelessComponentPageWithParams() throws Exception
+       {
+               PageParameters params = new PageParameters();
+               params.put("testParam1", "testValue1");
+               params.put("testParam2", "testValue2");
+
+               executeTest(StatelessComponentPageWithParams.class, params,
+                               "StatelessComponentPageWithParams_result.html");
+
+               tester.setupRequestAndResponse();
+               tester
+                               .getServletRequest()
+                               .setURL(
+                                               
"/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication?wicket:bookmarkablePage=:org.apache.wicket.stateless.StatelessComponentPageWithParams&testParam1=testValue1&testParam2=testValue2&wicket:interface=:0:link::ILinkListener::");
+               try
+               {
+                       tester.processRequestCycle();
+                       assertTrue(false);
+               }
+               catch (Exception e)
+               {
+                       assertEquals("wanted exception", e.getMessage());
+               }
+
+       }
+
+       /**
+        * @throws Exception
+        */
+       public void testStatelessComponentPageWithParamsWithMount() throws 
Exception
+       {
+               PageParameters params = new PageParameters();
+               params.put("testParam1", "testValue1");
+               params.put("testParam2", "testValue2");
+               tester.getApplication().mountBookmarkablePage("/stateless",
+                               StatelessComponentPageWithParams.class);
+               // test is always the home page. it doesn't work then
+               executeTest(StatelessComponentPageWithParams.class, params,
+                               
"StatelessComponentPageWithParams_mount_result.html");
+               tester.setupRequestAndResponse();
+               tester
+                               .getServletRequest()
+                               .setURL(
+                                               
"/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/stateless/testParam1/testValue1/testParam2/testValue2/wicket:interface/%3A0%3Alink%3A%3AILinkListener%3A%3A/");
+               try
+               {
+                       tester.processRequestCycle();
+                       fail("An exception should have been thrown for this 
request!");
+               }
+               catch (Exception e)
+               {
+                       assertEquals("wanted exception", e.getMessage());
+               }
+       }
+
+       /**
+        * @throws Exception
+        */
+       public void testStatelessComponentPageWithParamsWithIndexMount() throws 
Exception
+       {
+               PageParameters params = new PageParameters();
+               params.put("0", "testValue1");
+               params.put("1", "testValue2");
+               tester.getApplication().mount(
+                               new IndexedParamUrlCodingStrategy("/stateless",
+                                               
StatelessComponentPageWithParams.class));
+               // test is always the home page. it doesn't work then
+               executeTest(StatelessComponentPageWithParams.class, params,
+                               
"StatelessComponentPageWithParams_indexed_mount_result.html");
+               tester.setupRequestAndResponse();
+               tester
+                               .getServletRequest()
+                               .setURL(
+                                               
"/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/stateless/testValue1/testValue2/wicket:interface/%3A0%3Alink%3A%3AILinkListener%3A%3A/");
+               try
+               {
+                       tester.processRequestCycle();
+                       fail("An exception should have been thrown for this 
request!");
+               }
+               catch (Exception e)
+               {
+                       assertEquals("wanted exception", e.getMessage());
+               }
+       }
 }


Reply via email to