From 2a411b572ebe0ed28c7196540b6b26f80a425d36 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Mon, 25 Nov 2024 00:41:16 -0300 Subject: [PATCH] WICKET-7134 Form code refactoring - centralizing form processing code inside the visit - replacing form#isSubmitted with form#isVisible/EnabledInHierarchy --- .../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 2c40d09a41..6caf7d0290 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 @@ -1325,7 +1325,7 @@ protected void delegateSubmit(IFormSubmitter submittingComponent) // collect all forms innermost to outermost before any hierarchy is changed final List> forms = Generics.newArrayList(3); visitFormsPostOrder(processingForm, (form, visit) -> { - if (form.isSubmitted()) + if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy()) { forms.add(form); } @@ -1557,22 +1557,9 @@ public void component(final FormComponent formComponent, IVisit visit) * 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(); } @@ -1879,24 +1866,9 @@ protected void onSubmit() * @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(); } @@ -1924,14 +1896,15 @@ private void internalUpdateFormComponentModels() */ 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(); + } + }); } /** @@ -1949,16 +1922,11 @@ protected void onValidate() private void internalOnValidateModelObjects() { visitFormsPostOrder(this, (form, visit) -> { - if (form == Form.this) - { - return; - } - if (form.isSubmitted()) + if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy()) { form.onValidateModelObjects(); } }); - onValidateModelObjects(); } /** @@ -2055,28 +2023,6 @@ protected final void validateFormValidators() } } - /** - * 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. *