if(preValidationErrorIfAny != null) {
feedbackOrNotifyAnyRecognizedError(preValidationErrorIfAny, form);
// skip validation, because would relate to old values
final EntityPage entityPage = new EntityPage(EntityPropertiesForm.this.getModelObject(), null);
EntityPropertiesForm.this.setResponsePage(entityPage);
} else {
// run Wicket's validation
super.validate();
}
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
super.onError(target, form);
toEditMode(target);
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
if (getForm().hasError()) {
// stay in edit mode
return;
}
final ObjectAdapter object = getEntityModel().getObject();
final Memento snapshotToRollbackToIfInvalid = new Memento(object);
// to perform object-level validation, we must apply the
// changes first
// contrast this with ActionPanel (for validating action
// arguments) where
// we do the validation prior to the execution of the
// action
getEntityModel().apply();
final String invalidReasonIfAny = getEntityModel().getReasonInvalidIfAny();
if (invalidReasonIfAny != null) {
getForm().error(invalidReasonIfAny);
snapshotToRollbackToIfInvalid.recreateObject();
toEditMode(null);
return;
}
try {
EntityPropertiesForm.this.getTransactionManager().flushTransaction();
} catch(RuntimeException ex) {
// There's no need to abort the transaction here, as it will have already been done
// (in IsisTransactionManager#executeWithinTransaction(...)).
String message = recognizeExceptionAndNotify(ex, EntityPropertiesForm.this);
if(message == null) {
throw ex;
}
toEditMode(target);
return;
}
try {
getEntityModel().resetPropertyModels();
} catch(RuntimeException ex) {
throw ex;
}
toViewMode(null);
// "redirect-after-post"
//
// RequestCycle.get().getActiveRequestHandler() indicates this is handled by the ListenerInterfaceRequestHandler
// which renders page at end.
//
// it's necessary to zap the page parameters (so mapping is to just wicket/page?nn)
// otherwise (what I think happens) is that the httpServletResponse.sendRedirect ends up being to the same URL,
// and this is rejected as invalid either by the browser or by the servlet container (perhaps only if running remotely).
//
final EntityPage entityPage = new EntityPage(EntityPropertiesForm.this.getModelObject(), null);
EntityPropertiesForm.this.setResponsePage(entityPage);
}
};