wicket-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pekka Enberg <penb...@ri.fi>
Subject [RFC/PATCH 2/3] Use IFormListener for form processing
Date Wed, 04 Oct 2006 12:52:34 GMT
From: Pekka Enberg <penberg@cs.helsinki.fi>

Traverse all children that implement IFormListener interface as we want
non-form components to be able to stop processing of child components too.

Cc: Igor Vaynberg <igor.vaynberg@gmail.com>
Cc: Janne Hietamäki <janne.hietamaki@ri.fi>
Cc: Joni Freeman <joni.freeman@ri.fi>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 src/java/wicket/markup/html/form/Form.java          |    6 ++---
 src/java/wicket/markup/html/form/FormComponent.java |   11 +++++----
 src/java/wicket/markup/html/form/IFormListener.java |   23 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 8 deletions(-)

Index: wicket/src/java/wicket/markup/html/form/IFormListener.java
===================================================================
--- /dev/null
+++ wicket/src/java/wicket/markup/html/form/IFormListener.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+/**
+ * Listener interface that is called when a form is processed.
+ *
+ * @author Pekka Enberg
+ */
+public interface IFormListener
+{
+}
Index: wicket/src/java/wicket/markup/html/form/Form.java
===================================================================
--- wicket.orig/src/java/wicket/markup/html/form/Form.java
+++ wicket/src/java/wicket/markup/html/form/Form.java
@@ -479,11 +479,11 @@ public class Form<T> extends WebMarkupCo
 	 */
 	public final void visitFormComponents(final FormComponent.IVisitor visitor)
 	{
-		visitChildren(FormComponent.class, new IVisitor()
+		visitChildren(IFormListener.class, new IVisitor()
 		{
 			public Object component(final Component component)
 			{
-				return visitor.formComponent((FormComponent)component);
+				return visitor.formComponent((IFormListener)component);
 			}
 		});
 
@@ -505,7 +505,7 @@ public class Form<T> extends WebMarkupCo
 				Component child = (Component)iter.next();
 				if (child instanceof FormComponent)
 				{
-					visitor.formComponent((FormComponent)child);
+					visitor.formComponent((IFormListener)child);
 				}
 			}
 		}
Index: wicket/src/java/wicket/markup/html/form/FormComponent.java
===================================================================
--- wicket.orig/src/java/wicket/markup/html/form/FormComponent.java
+++ wicket/src/java/wicket/markup/html/form/FormComponent.java
@@ -33,7 +33,6 @@ import wicket.Localizer;
 import wicket.MarkupContainer;
 import wicket.Page;
 import wicket.WicketRuntimeException;
-import wicket.Component.IVisitor;
 import wicket.markup.ComponentTag;
 import wicket.markup.html.WebMarkupContainer;
 import wicket.model.IAssignmentAware;
@@ -100,7 +99,7 @@ import wicket.version.undo.Change;
  * @author Johan Compagner
  * @author Igor Vaynberg (ivaynberg)
  */
-public abstract class FormComponent<T> extends WebMarkupContainer<T>
+public abstract class FormComponent<T> extends WebMarkupContainer<T> implements
IFormListener
 {
 	private static final long serialVersionUID = 1L;
 
@@ -122,7 +121,7 @@ public abstract class FormComponent<T> e
 		 * @param formComponent
 		 *            The form component
 		 */
-		public Object formComponent(FormComponent formComponent);
+		public Object formComponent(IFormListener formComponent);
 	}
 
 	public static abstract class AbstractVisitor implements IVisitor
@@ -130,9 +129,11 @@ public abstract class FormComponent<T> e
 		/**
 		 * @see wicket.markup.html.form.FormComponent.IVisitor#formComponent(wicket.markup.html.form.FormComponent)
 		 */
-		public Object formComponent(FormComponent formComponent)
+		public Object formComponent(IFormListener component)
 		{
-			onFormComponent(formComponent);
+			if (component instanceof FormComponent) {
+				onFormComponent((FormComponent) component);
+			}
 			return Component.IVisitor.CONTINUE_TRAVERSAL;
 		}
 



Mime
View raw message