Author: gseitz
Date: Fri Mar  7 17:00:44 2008
New Revision: 634880

URL: http://svn.apache.org/viewvc?rev=634880&view=rev
Log:
WICKET-1397

Added:
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html
   (with props)
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java
   (with props)
Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
    
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java?rev=634880&r1=634879&r2=634880&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
 Fri Mar  7 17:00:44 2008
@@ -27,37 +27,37 @@
 /**
  * A link that submits a form via ajax. Since this link takes the form as a 
constructor argument it
  * does not need to be inside form's component hierarchy.
- * 
+ *
  * <p/> It works by splitting the javascript/Ajax calls from the normal 
non-ajax requests by
  * generating:
- * 
+ *
  * <pre>
  * &lt;a href=&quot;normal action url&quot; onclick=&quot;ajax javascript 
script; return
  * false;&quot;&gt;link&lt;/a&gt;
  * </pre>
- * 
+ *
  * If/when javascript is turned off in the browser, or it doesn't support 
javascript, then the
  * browser will not respond to the onclick event, using the href directly. 
Wicket will then use a
  * normal request target, and call the serverside onClick with a null [EMAIL 
PROTECTED] AjaxRequestTarget}.
- * 
+ *
  * If javascript is enabled, Wicket will send an ajax request, and process it 
serverside with an
  * [EMAIL PROTECTED] AjaxRequestTarget} that is supplied to the server-side 
onClick method. The "return false"
  * in the &lt;a href&gt; onclick handler ensures the browser doesn't perform 
the normal request too.
- * 
+ *
  * The latter is nicely illustrated with this:
- * 
+ *
  * <pre>
  * &lt;a href=&quot;javascript:alert('href event handler');&quot;
  * onclick=&quot;alert('onclick event handler');&quot;&gt;clicking me gives two
  * alerts&lt;/a&gt;
- * 
+ *
  * &lt;a href=&quot;javascript:alert('href event handler');&quot;
  * onclick=&quot;alert('onclick event handler');return 
false;&quot;&gt;clicking me
  * gives only one alert&lt;/a&gt;
  * </pre>
- * 
+ *
  * @since 1.2
- * 
+ *
  * @author Igor Vaynberg (ivaynberg)
  */
 public abstract class AjaxSubmitLink extends AbstractSubmitLink
@@ -66,7 +66,7 @@
 
        /**
         * Construct.
-        * 
+        *
         * @param id
         */
        public AjaxSubmitLink(String id)
@@ -76,7 +76,7 @@
 
        /**
         * Construct.
-        * 
+        *
         * @param id
         * @param form
         */
@@ -91,12 +91,12 @@
 
                        protected void onSubmit(AjaxRequestTarget target)
                        {
-                               AjaxSubmitLink.this.onSubmit(target, form);
+                               AjaxSubmitLink.this.onSubmit(target, getForm());
                        }
 
                        protected void onError(AjaxRequestTarget target)
                        {
-                               AjaxSubmitLink.this.onError(target, form);
+                               AjaxSubmitLink.this.onError(target, getForm());
                        }
 
                        protected CharSequence getEventHandler()
@@ -124,7 +124,7 @@
        /**
         * Returns the [EMAIL PROTECTED] IAjaxCallDecorator} that will be used 
to modify the generated javascript.
         * This is the preferred way of changing the javascript in the onclick 
handler
-        * 
+        *
         * @return call decorator used to modify the generated javascript or 
null for none
         */
        protected IAjaxCallDecorator getAjaxCallDecorator()
@@ -152,7 +152,7 @@
        /**
         * Final implementation of the Button's onSubmit. AjaxSubmitLinks have 
there own onSubmit which
         * is called.
-        * 
+        *
         * @see org.apache.wicket.markup.html.form.Button#onSubmit()
         */
        public final void onSubmit()
@@ -161,7 +161,7 @@
 
        /**
         * Listener method invoked on form submit
-        * 
+        *
         * @param target
         * @param form
         */
@@ -169,10 +169,10 @@
 
        /**
         * Listener method invoked on form submit with errors
-        * 
+        *
         * @param target
         * @param form
-        * 
+        *
         * TODO 1.3: Make abstract to be consistent with onsubmit()
         */
        protected void onError(AjaxRequestTarget target, Form form)

Modified: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java?rev=634880&r1=634879&r2=634880&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java
 Fri Mar  7 17:00:44 2008
@@ -54,6 +54,51 @@
        /**
         * 
         */
+       public void testClickLinkInsideForm_ajaxSubmitLink()
+       {
+               MockPojo mockPojo = new MockPageWithFormAndLink.MockPojo();
+               mockPojo.setName("Mock name");
+
+               final MockPageWithFormAndContainedLink page = new 
MockPageWithFormAndContainedLink(mockPojo);
+               page.addLink(new AjaxSubmitLink("link")
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       protected void onSubmit(AjaxRequestTarget target, Form 
form)
+                       {
+                               assertNotNull(form);
+                               linkClicked = true;
+                       }
+               });
+
+               tester.startPage(new ITestPageSource()
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       public Page getTestPage()
+                       {
+                               return page;
+                       }
+               });
+
+               
tester.assertRenderedPage(MockPageWithFormAndContainedLink.class);
+
+               // Change the name in the textfield
+               page.getNameField().setModelValue(new String[] { "new mock 
value" });
+
+               // Click the submit link
+               tester.clickLink("form:link");
+
+               // Has it really been clicked?
+               assertTrue(linkClicked);
+
+               // And has the form been "submitted"
+               assertEquals("new mock value", mockPojo.getName());
+       }
+
+       /**
+        * 
+        */
        public void testClickLink_ajaxSubmitLink()
        {
                MockPojo mockPojo = new MockPageWithFormAndLink.MockPojo();
@@ -66,6 +111,7 @@
 
                        protected void onSubmit(AjaxRequestTarget target, Form 
form)
                        {
+                               assertNotNull(form);
                                linkClicked = true;
                        }
                };
@@ -84,7 +130,7 @@
                tester.assertRenderedPage(MockPageWithFormAndLink.class);
 
                // Change the name in the textfield
-               page.getNameField().setModelValue("new mock value");
+               page.getNameField().setModelValue(new String[] { "new mock 
value" });
 
                // Click the submit link
                tester.clickLink("link");

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html?rev=634880&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html
 Fri Mar  7 17:00:44 2008
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+<form wicket:id="form">
+<input type="text" wicket:id="name" />
+<a href="#" wicket:id="link">Link</a>
+</form>
+</body>
+</html>
\ No newline at end of file

Propchange: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java?rev=634880&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java
 (added)
+++ 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java
 Fri Mar  7 17:00:44 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.util.tester.apps_5;
+
+import org.apache.wicket.markup.html.link.AbstractLink;
+
+/**
+ * Contains a form with a textfield on it and a link inside the form. Use the
+ * [EMAIL PROTECTED] #addLink(AbstractLink)} method to add a link to the form.
+ *
+ * @author Gerolf Seitz
+ */
+public class MockPageWithFormAndContainedLink extends MockPageWithFormAndLink
+{
+
+       /**
+        * Construct.
+        *
+        * @param mockPojo
+        */
+       public MockPageWithFormAndContainedLink(MockPojo mockPojo)
+       {
+               super(mockPojo);
+       }
+
+       /**
+        * @param link
+        */
+       public void addLink(AbstractLink link)
+       {
+               getForm().add(link);
+       }
+
+}

Propchange: 
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/apps_5/MockPageWithFormAndContainedLink.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to