THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
Excerpt | ||
---|---|---|
| ||
How to use multiple submit buttons in forms |
When we have a form with only one submit button, the default Form's onSubmit() method will be called. If the Form has more than one submit button, then the mechanism works differently.
...
We have a simple Form that contains two submit buttons. The class contructor looks something like this:
Panel |
---|
Code Block |
public CustomForm(String form) {
add(new OkayButton());
Button cancel = new CancelButton();
cancel.setDefaultFormProcessing(false);
add(cancel);
}
|
Note: without setDefaultFormProcessing(false), the "cancel" button is subject to validation like the "Ok" button.
The we have two custom Button classes with the override onSubmit() that looks something like below:
Code Block | |
---|---|
Panel | |
Wiki Markup |
//This method is in OkayButton class
public void onSubmit() {
//what to do when this "Ok" button is click
log.info("Ok button pressed");
}
|
Panel | |
Wiki Markup |
//This method is in CancelButton class
public void onSubmit() {
//Do the "Cancel" thing when click
log.info("Cancel button pressed");
}
|
Alternatively, this can also be done with anonymous inner classes, e.g.
Code Block | |
---|---|
Panel | |
Wiki Markup |
private static class MyForm extends Form {
public MyForm(String name) {
super(name);
add(new Button("okbutton"){
protected void onSubmit() {
info("OK was pressed!");
}
});
Button cancel = new Button("cancelbutton"){
protected void onSubmit() {
info("Cancel was pressed!");
}
};
cancel.setDefaultFormProcessing(false);
add(cancel);
}
}
|
with the HTML being
Code Block | ||||
---|---|---|---|---|
| ||||
<form | ||||
Panel | ||||
<form ...> <input <input type="submit" wicket:id="okbutton value="OK" /> <input <input type="submit" wicket:id="cancelbutton value="Cancel" /> </form> |