@Override
public void onSubmit() {
if (!getForm().hasError()) {
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();
return;
} else {
toViewMode(null);
}
} else {