API / Apache Wicket Interview questions
What is the difference between onSubmit() and onError() in a Wicket Form?
These are the two possible outcomes of a form submission, and only one of them runs for any given submit — they represent the success and failure branches of the same validation pipeline.
| onSubmit() | onError() |
| Runs when every field and form-level validation passes | Runs when any field or form-level validation fails |
| Model has already been updated with validated values | Model is left untouched; invalid input isn't written to it |
| Typical use: persist data, redirect via setResponsePage() | Typical use: log the failed attempt, add a custom feedback message |
A Button attached to a form can also have its own onSubmit()/onError() pair distinct from the enclosing Form's, which is how a page with multiple submit buttons (say, "Save Draft" versus "Publish") can run different logic depending on which button actually triggered the submission, while still sharing the same set of validated fields underneath.
More Related questions...