Hi,

I need  an ajax  submit button  that does  not validate  the form.
Therefore I noticed in trunk the new IFormSubmittingComponent that
works with Button, SubmitLink and AjaxSubmitButton.

I backported  that feature to branch  wicket 1.x, but I  need your
advice prior  to filing the  patch in  Jira, as the  visibility of
method onSubmit() has changed from  protected to public, which may
cause backwards compatibility problem.

If compatibility is an issue for branch 1.x, I propose to backport
the feature without  using the interface IFormSubmittingComponent,
but  using Button.   Indeed SubmitLink  and AjaxSubmitButton  both
extend Button, so using the interface is not mandatory.

WDYT?  See attached patch for reference.
-- 
     Jean-Baptiste Quenot
aka  John Banana Qwerty
http://caraldi.com/jbq/
Index: src/test/java/wicket/FormDispatchEventTest.java
===================================================================
--- src/test/java/wicket/FormDispatchEventTest.java     (revision 462721)
+++ src/test/java/wicket/FormDispatchEventTest.java     (working copy)
@@ -18,8 +18,6 @@
 
 import java.util.ArrayList;
 
-import wicket.IRedirectListener;
-import wicket.RequestCycle;
 import wicket.markup.html.form.DropDownChoice;
 import wicket.markup.html.form.Form;
 import wicket.markup.html.form.IOnChangeListener;
Index: src/test/java/wicket/util/tester/apps_3/ChoicePage.java
===================================================================
--- src/test/java/wicket/util/tester/apps_3/ChoicePage.java     (revision 
462721)
+++ src/test/java/wicket/util/tester/apps_3/ChoicePage.java     (working copy)
@@ -101,7 +101,7 @@
                {
                        private static final long serialVersionUID = 1L;
 
-                       protected void onSubmit()
+                       public void onSubmit()
                        {
                                anotherButtonPressed = true;
                        }
Index: src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java
===================================================================
--- src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java    
(revision 462721)
+++ src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java    
(working copy)
@@ -22,9 +22,9 @@
 import wicket.ajax.IAjaxCallDecorator;
 import wicket.ajax.form.AjaxFormSubmitBehavior;
 import wicket.markup.ComponentTag;
-import wicket.markup.html.WebComponent;
 import wicket.markup.html.form.Button;
 import wicket.markup.html.form.Form;
+import wicket.markup.html.form.IFormSubmittingComponent;
 import wicket.util.string.AppendingStringBuffer;
 
 /**
@@ -36,7 +36,7 @@
  * 
  * @author Igor Vaynberg (ivaynberg)
  */
-public abstract class AjaxSubmitButton extends WebComponent
+public abstract class AjaxSubmitButton extends Button
 {
        private static final long serialVersionUID = 1L;
 
Index: src/main/java/wicket/markup/html/form/IFormSubmittingComponent.java
===================================================================
--- src/main/java/wicket/markup/html/form/IFormSubmittingComponent.java 
(revision 0)
+++ src/main/java/wicket/markup/html/form/IFormSubmittingComponent.java 
(revision 0)
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ * $Revision: 5004 $
+ * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
+ * 
+ * 
==============================================================================
+ * Licensed 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 wicket.markup.html.form;
+
+/**
+ * Interface that must be implemented by components that are able to submit
+ * form.
+ * 
+ * @author Matej Knopp
+ */
+public interface IFormSubmittingComponent
+{
+       /**
+        * Returns whether form should be processed the default way. When false
+        * (default is true), all validation and formupdating is bypassed and 
the
+        * onSubmit method of that button is called directly, and the onSubmit
+        * method of the parent form is not called. A common use for this is to
+        * create a cancel button.
+        * 
+        * @return defaultFormProcessing
+        */
+       public boolean getDefaultFormProcessing();
+
+
+       /**
+        * Returns the name that is unique to this component, at least within 
the
+        * form.
+        * 
+        * @return component name
+        */
+       public String getInputName();
+       
+       /**
+        * Returns the form this component submits.
+        * 
+        * @return form submitted by this component
+        */
+       public Form getForm();
+       
+       /**
+        * Override this method to provide special submit handling in a 
multi-button
+        * form. It is called whenever the user clicks this particular button.
+        */
+       public void onSubmit();
+}

Property changes on: 
src/main/java/wicket/markup/html/form/IFormSubmittingComponent.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Index: src/main/java/wicket/markup/html/form/SubmitLink.java
===================================================================
--- src/main/java/wicket/markup/html/form/SubmitLink.java       (revision 
462721)
+++ src/main/java/wicket/markup/html/form/SubmitLink.java       (working copy)
@@ -68,7 +68,7 @@
  * @author Igor Vaynberg (ivaynberg)
  * @author Eelco Hillenius
  */
-public class SubmitLink extends Button implements ILinkListener
+public class SubmitLink extends Button
 {
        private static final long serialVersionUID = 1L;
 
Index: src/main/java/wicket/markup/html/form/Form.java
===================================================================
--- src/main/java/wicket/markup/html/form/Form.java     (revision 462721)
+++ src/main/java/wicket/markup/html/form/Form.java     (working copy)
@@ -295,7 +295,7 @@
                        else
                        {
                                // First, see if the processing was triggered 
by a Wicket button
-                               final Button submittingButton = 
findSubmittingButton();
+                               final IFormSubmittingComponent submittingButton 
= findSubmittingButton();
 
                                // When processing was triggered by a Wicket 
button and that
                                // button indicates it wants to be called 
immediately
@@ -559,7 +559,7 @@
         *            processing was triggered by something else (like a 
non-Wicket
         *            submit button or a javascript execution)
         */
-       protected void delegateSubmit(Button submittingButton)
+       protected void delegateSubmit(IFormSubmittingComponent submittingButton)
        {
                // when the given button is not null, it means that it was the
                // submitting button
@@ -578,55 +578,34 @@
         * @return The button which submitted this form or null if the 
processing
         *         was not trigger by a registered button component
         */
-       public final Button findSubmittingButton()
+       public final IFormSubmittingComponent findSubmittingButton()
        {
-               Button button = (Button)visitChildren(Button.class, new 
IVisitor()
-               {
-                       public Object component(final Component component)
-                       {
-                               // Get button
-                               final Button button = (Button)component;
-
-                               // Check for button-name or button-name.x 
request string
-                               if 
(getRequest().getParameter(button.getInputName()) != null
-                                               || 
getRequest().getParameter(button.getInputName() + ".x") != null)
+               IFormSubmittingComponent submit = 
(IFormSubmittingComponent)getPage().visitChildren(
+                               IFormSubmittingComponent.class, new IVisitor()
                                {
-                                       if (!button.isVisible())
+                                       public Object component(final Component 
component)
                                        {
-                                               throw new 
WicketRuntimeException("Submit Button " + button.getInputName()
-                                                               + " (path=" + 
button.getPageRelativePath() + ") is not visible");
-                                       }
-                                       return button;
-                               }
-                               return CONTINUE_TRAVERSAL;
-                       }
-               });
+                                               // Get button
+                                               final IFormSubmittingComponent 
submit = (IFormSubmittingComponent)component;
 
-               if (button == null)
-               {
-                       button = 
(Button)getPage().visitChildren(SubmitLink.class, new IVisitor()
-                       {
-                               public Object component(final Component 
component)
-                               {
-                                       // Get button
-                                       final SubmitLink button = 
(SubmitLink)component;
-
-                                       // Check for button-name or 
button-name.x request string
-                                       if (button.getForm() == Form.this
-                                                       && 
(getRequest().getParameter(button.getInputName()) != null || getRequest()
-                                                                       
.getParameter(button.getInputName() + ".x") != null))
-                                       {
-                                               if (!button.isVisible())
+                                               // Check for button-name or 
button-name.x request string
+                                               if (submit.getForm() == 
Form.this
+                                                               && 
(getRequest().getParameter(submit.getInputName()) != null || getRequest()
+                                                                               
.getParameter(submit.getInputName() + ".x") != null))
                                                {
-                                                       throw new 
WicketRuntimeException("Submit Button is not visible");
+                                                       if 
(!component.isVisible())
+                                                       {
+                                                               throw new 
WicketRuntimeException("Submit Button "
+                                                                               
+ submit.getInputName() + " (path="
+                                                                               
+ component.getPageRelativePath() + ") is not visible");
+                                                       }
+                                                       return submit;
                                                }
-                                               return button;
+                                               return CONTINUE_TRAVERSAL;
                                        }
-                                       return CONTINUE_TRAVERSAL;
-                               }
-                       });
-               }
-               return button;
+                               });
+
+               return submit;
        }
 
        /**
Index: src/main/java/wicket/markup/html/form/Button.java
===================================================================
--- src/main/java/wicket/markup/html/form/Button.java   (revision 462721)
+++ src/main/java/wicket/markup/html/form/Button.java   (working copy)
@@ -53,7 +53,7 @@
  * @author Jonathan Locke
  * @author Eelco Hillenius
  */
-public class Button extends FormComponent
+public class Button extends FormComponent implements IFormSubmittingComponent
 {
        private static final long serialVersionUID = 1L;
 
@@ -219,7 +219,7 @@
         * Override this method to provide special submit handling in a 
multi-button
         * form. It is called whenever the user clicks this particular button.
         */
-       protected void onSubmit()
+       public void onSubmit()
        {
        }
 }
\ No newline at end of file

Reply via email to