wicket.markup.html.form.Button
[back to the reference]Within a form, you can nest Button components. Note that you don't have to do this to let the form work (a simple <input type="submit".. suffices), but if you want to have different kinds of submit behaviour it might be a good idea to use Buttons.
When you add a Wicket Button to a form, and that button is clicked, by default the button's onSubmit method is called first, and after that the form's onSubmit button is called. If you want to change this (e.g. you don't want to call the form's onSubmit method, or you want it called before the button's onSubmit method), you can override Form.delegateSubmit.
One other option you should know of is the 'defaultFormProcessing' property of Button components. When you set this to false (default is true), all validation and form updating is bypassed, the onSubmit method of that button is called directly, and the onSubmit method of the parent form is not called. A common use for this is to create a cancel button.
Behind the Scenes
Example HTML
<form wicket:id="form">
<input type="submit" value="non wicket submit button" />
<input wicket:id="button1" type="submit" value="default wicket button" />
<input wicket:id="button2" type="submit" value="wicket button with setDefaultFormProcessing(false)" />
</form>
Example Code
// Add a form with an onSubmit implementation that sets a message
Form form = new Form("form") {
protected void onSubmit() {
info("Form.onSubmit executed");
}
};
Button button1 = new Button("button1") {
protected void onSubmit() {
info("button1.onSubmit executed");
}
};
form.add(button1);
Button button2 = new Button("button2") {
protected void onSubmit() {
info("button2.onSubmit executed");
}
};
button2.setDefaultFormProcessing(false);
form.add(button2);
add(form);