Wicket: error while processing form; how to skip to onError()?

2.3k Views Asked by At

I have an AjaxFallbackButton on my page with its onSubmit and onError methods overridden. What is the best practice for dealing with exceptions/errors in the onSubmit method? Should I just stop processing it, register the error and call onError like this:

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
   ... // error 
      form.error("An exception was thrown")
      onError();
      return;
}

or is there a better way?

1

There are 1 best solutions below

0
On BEST ANSWER

Unless you have specific logic in onError (like setting a response page, rolling back a transaction, etc), Wicket doesn't demand you calling it.

In any case, there is no alternative, other than ensuring you check everything in validators attached to your form components and form, thus preventing the exception from ever happening in the first place.