I have a form to add an entity to the database. This form has a Save and Cancel button and also two input fields which are marked with required.
While the save functionality works fine, the cancel functionality does not work as expected: clicking cancel should bring the user back to another page but it should not validate the form.
Form<AddEntityPage> form = new Form<>("form_1", new CompoundPropertyModel<>(this));
form.add(new RequiredTextField<>("name"));
...
form.add(new Button("cancel_button") {
@Override
public void onSubmit() {
setResponsePage(ViewEntityPage.class);
}
});
<form wicket:id="form_1">
<table>
...
<tr>
<td>
<button name="cancel"
value="Cancel"
wicket:id="cancel_button">Cancel</button>
</td>
...
</tr>
</table>
</form>
So what is the ideal way for aborting form processing? I simple to enforce the navigation to the response page.

You need to do
cancelButton.setDefaultFormProcessing(false).As its javadoc says: