Skip to content

Commit 2a411b5

Browse files
committed
WICKET-7134 Form code refactoring
- centralizing form processing code inside the visit - replacing form#isSubmitted with form#isVisible/EnabledInHierarchy
1 parent f67bccf commit 2a411b5

File tree

1 file changed

+13
-67
lines changed
  • wicket-core/src/main/java/org/apache/wicket/markup/html/form

1 file changed

+13
-67
lines changed

wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java

+13-67
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ protected void delegateSubmit(IFormSubmitter submittingComponent)
13251325
// collect all forms innermost to outermost before any hierarchy is changed
13261326
final List<Form<?>> forms = Generics.newArrayList(3);
13271327
visitFormsPostOrder(processingForm, (form, visit) -> {
1328-
if (form.isSubmitted())
1328+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
13291329
{
13301330
forms.add(form);
13311331
}
@@ -1557,22 +1557,9 @@ public void component(final FormComponent<?> formComponent, IVisit<Void> visit)
15571557
* Mark each form component on this form and on nested forms valid.
15581558
*/
15591559
protected final void markFormComponentsValid()
1560-
{
1561-
markNestedFormComponentsValid();
1562-
internalMarkFormComponentsValid();
1563-
}
1564-
1565-
/**
1566-
* Mark each form component on nested form valid.
1567-
*/
1568-
private void markNestedFormComponentsValid()
15691560
{
15701561
visitFormsPostOrder(this, (form, visit) -> {
1571-
if (form == Form.this)
1572-
{
1573-
return;
1574-
}
1575-
if (form.isSubmitted())
1562+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
15761563
{
15771564
form.internalMarkFormComponentsValid();
15781565
}
@@ -1879,24 +1866,9 @@ protected void onSubmit()
18791866
* @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
18801867
*/
18811868
protected final void updateFormComponentModels()
1882-
{
1883-
updateNestedFormComponentModels();
1884-
internalUpdateFormComponentModels();
1885-
}
1886-
1887-
/**
1888-
* Update the model of all components on nested forms.
1889-
*
1890-
* @see #updateFormComponentModels()
1891-
*/
1892-
private void updateNestedFormComponentModels()
18931869
{
18941870
visitFormsPostOrder(this, (form, visit) -> {
1895-
if (form == Form.this)
1896-
{
1897-
return;
1898-
}
1899-
if (form.isSubmitted())
1871+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
19001872
{
19011873
form.internalUpdateFormComponentModels();
19021874
}
@@ -1924,14 +1896,15 @@ private void internalUpdateFormComponentModels()
19241896
*/
19251897
protected final void validate()
19261898
{
1927-
// since this method can be called directly by users, this additional check is needed
1928-
if (isEnabledInHierarchy() && isVisibleInHierarchy())
1929-
{
1930-
validateNestedForms();
1931-
validateComponents();
1932-
validateFormValidators();
1933-
onValidate();
1934-
}
1899+
visitFormsPostOrder(this, (form, visit) -> {
1900+
// since this method can be called directly by users, this additional check is needed
1901+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
1902+
{
1903+
form.validateComponents();
1904+
form.validateFormValidators();
1905+
form.onValidate();
1906+
}
1907+
});
19351908
}
19361909

19371910
/**
@@ -1949,16 +1922,11 @@ protected void onValidate()
19491922
private void internalOnValidateModelObjects()
19501923
{
19511924
visitFormsPostOrder(this, (form, visit) -> {
1952-
if (form == Form.this)
1953-
{
1954-
return;
1955-
}
1956-
if (form.isSubmitted())
1925+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
19571926
{
19581927
form.onValidateModelObjects();
19591928
}
19601929
});
1961-
onValidateModelObjects();
19621930
}
19631931

19641932
/**
@@ -2055,28 +2023,6 @@ protected final void validateFormValidators()
20552023
}
20562024
}
20572025

2058-
/**
2059-
* Validates {@link FormComponent}s as well as {@link IFormValidator}s in nested {@link Form}s.
2060-
*
2061-
* @see #validate()
2062-
*/
2063-
private void validateNestedForms()
2064-
{
2065-
visitFormsPostOrder(this, (form, visit) -> {
2066-
if (form == Form.this)
2067-
{
2068-
return;
2069-
}
2070-
2071-
if (form.isSubmitted())
2072-
{
2073-
form.validateComponents();
2074-
form.validateFormValidators();
2075-
form.onValidate();
2076-
}
2077-
});
2078-
}
2079-
20802026
/**
20812027
* Allows to customize input names of form components inside this form.
20822028
*

0 commit comments

Comments
 (0)