You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pe...@apache.org on 2025/02/06 01:05:50 UTC

(wicket) branch master updated: WICKET-7134 Form code refactoring

This is an automated email from the ASF dual-hosted git repository.

pedro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 61d67f762e WICKET-7134 Form code refactoring
61d67f762e is described below

commit 61d67f762e61447d781914fa41629aa75b05a972
Author: Pedro Santos <pe...@apache.org>
AuthorDate: Mon Nov 25 00:41:16 2024 -0300

    WICKET-7134 Form code refactoring
    
    - centralizing form processing code inside the visit
    - replacing form#isSubmitted with form#isVisible/EnabledInHierarchy
---
 .../org/apache/wicket/markup/html/form/Form.java   | 80 ++++------------------
 1 file changed, 13 insertions(+), 67 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
index f8dcaf072d..0a9326ad7c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
@@ -1323,7 +1323,7 @@ public class Form<T> extends WebMarkupContainer
 		// collect all forms innermost to outermost before any hierarchy is changed
 		final List<Form<?>> forms = Generics.newArrayList(3);
 		visitFormsPostOrder(processingForm, (form, visit) -> {
-			if (form.isSubmitted())
+			if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
 			{
 				forms.add(form);
 			}
@@ -1555,22 +1555,9 @@ public class Form<T> extends WebMarkupContainer
 	 * Mark each form component on this form and on nested forms valid.
 	 */
 	protected final void markFormComponentsValid()
-	{
-		markNestedFormComponentsValid();
-		internalMarkFormComponentsValid();
-	}
-
-	/**
-	 * Mark each form component on nested form valid.
-	 */
-	private void markNestedFormComponentsValid()
 	{
 		visitFormsPostOrder(this, (form, visit) -> {
-			if (form == Form.this)
-			{
-				return;
-			}
-			if (form.isSubmitted())
+			if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
 			{
 				form.internalMarkFormComponentsValid();
 			}
@@ -1877,24 +1864,9 @@ public class Form<T> extends WebMarkupContainer
 	 * @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
 	 */
 	protected final void updateFormComponentModels()
-	{
-		updateNestedFormComponentModels();
-		internalUpdateFormComponentModels();
-	}
-
-	/**
-	 * Update the model of all components on nested forms.
-	 *
-	 * @see #updateFormComponentModels()
-	 */
-	private void updateNestedFormComponentModels()
 	{
 		visitFormsPostOrder(this, (form, visit) -> {
-			if (form == Form.this)
-			{
-				return;
-			}
-			if (form.isSubmitted())
+			if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
 			{
 				form.internalUpdateFormComponentModels();
 			}
@@ -1922,14 +1894,15 @@ public class Form<T> extends WebMarkupContainer
 	 */
 	protected final void validate()
 	{
-		// since this method can be called directly by users, this additional check is needed
-		if (isEnabledInHierarchy() && isVisibleInHierarchy())
-		{
-			validateNestedForms();
-			validateComponents();
-			validateFormValidators();
-			onValidate();
-		}
+		visitFormsPostOrder(this, (form, visit) -> {
+			// since this method can be called directly by users, this additional check is needed
+			if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
+			{
+				form.validateComponents();
+				form.validateFormValidators();
+				form.onValidate();
+			}
+		});
 	}
 
 	/**
@@ -1947,16 +1920,11 @@ public class Form<T> extends WebMarkupContainer
 	private void internalOnValidateModelObjects()
 	{
 		visitFormsPostOrder(this, (form, visit) -> {
-			if (form == Form.this)
-			{
-				return;
-			}
-			if (form.isSubmitted())
+			if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
 			{
 				form.onValidateModelObjects();
 			}
 		});
-		onValidateModelObjects();
 	}
 
 	/**
@@ -2053,28 +2021,6 @@ public class Form<T> extends WebMarkupContainer
 		}
 	}
 
-	/**
-	 * Validates {@link FormComponent}s as well as {@link IFormValidator}s in nested {@link Form}s.
-	 *
-	 * @see #validate()
-	 */
-	private void validateNestedForms()
-	{
-		visitFormsPostOrder(this, (form, visit) -> {
-			if (form == Form.this)
-			{
-				return;
-			}
-
-			if (form.isSubmitted())
-			{
-				form.validateComponents();
-				form.validateFormValidators();
-				form.onValidate();
-			}
-		});
-	}
-
 	/**
 	 * Allows to customize input names of form components inside this form.
 	 *