Skip to content

Commit bba3544

Browse files
WICKET-7141 Add hook methods before and after update form components models (post order).
1 parent ca8ec27 commit bba3544

File tree

1 file changed

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

1 file changed

+56
-1
lines changed

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

+56-1
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,14 @@ public void process(IFormSubmitter submittingComponent)
10021002

10031003
// before updating, call the interception method for clients
10041004
beforeUpdateFormComponentModels();
1005+
internalOnBeforeUpdateFormComponentModels();
10051006

10061007
// Update model using form data
10071008
updateFormComponentModels();
10081009

1010+
// after updating, call the interception method for clients
1011+
internalOnAfterUpdateFormComponentModels();
1012+
10091013
// validate model objects after input values have been bound
10101014
internalOnValidateModelObjects();
10111015
if (hasError())
@@ -1288,15 +1292,66 @@ protected void addDefaultSubmitButtonHandler(IHeaderResponse headerResponse)
12881292
headerResponse.render(OnEventHeaderItem.forMarkupId(getMarkupId(), "keypress", script.toString()));
12891293
}
12901294

1295+
12911296
/**
12921297
* Template method to allow clients to do any processing (like recording the current model so
12931298
* that, in case onSubmit does further validation, the model can be rolled back) before the
12941299
* actual updating of form component models is done.
1295-
*/
1300+
*
1301+
* @deprecated Use {@linkplain #onBeforeUpdateFormComponentModels} instead.
1302+
*/
1303+
@Deprecated(since = "10.5.0", forRemoval = true)
12961304
protected void beforeUpdateFormComponentModels()
12971305
{
12981306
}
12991307

1308+
1309+
/**
1310+
* Calls {@linkplain #onBeforeUpdateFormComponentModels()} on this form and all nested forms that are
1311+
* visible and enabled.
1312+
*/
1313+
private void internalOnBeforeUpdateFormComponentModels()
1314+
{
1315+
visitFormsPostOrder(this, (form, visit) -> {
1316+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
1317+
{
1318+
form.onBeforeUpdateFormComponentModels();
1319+
}
1320+
});
1321+
}
1322+
1323+
/**
1324+
* Hook method to allow clients to do any processing (like recording the current model so
1325+
* that, in case onSubmit does further validation, the model can be rolled back) before the
1326+
* actual updating of form component models is done.
1327+
*/
1328+
protected void onBeforeUpdateFormComponentModels()
1329+
{
1330+
}
1331+
1332+
/**
1333+
* Calls {@linkplain #onAfterUpdateFormComponentModels()} on this form and all nested forms that are
1334+
* visible and enabled.
1335+
*/
1336+
private void internalOnAfterUpdateFormComponentModels()
1337+
{
1338+
visitFormsPostOrder(this, (form, visit) -> {
1339+
if (form.isVisibleInHierarchy() && form.isEnabledInHierarchy())
1340+
{
1341+
form.onAfterUpdateFormComponentModels();
1342+
}
1343+
});
1344+
}
1345+
1346+
/**
1347+
* Hook method to allow clients to do any processing (like updating entities or DTO from the models
1348+
* to be used later on the next late-stage validation) after the actual updating of form component
1349+
* models is done.
1350+
*/
1351+
protected void onAfterUpdateFormComponentModels()
1352+
{
1353+
}
1354+
13001355
/**
13011356
* Called (by the default implementation of 'process') when all fields validated, the form was
13021357
* updated and it's data was allowed to be persisted. It is meant for delegating further

0 commit comments

Comments
 (0)