If you have an AJAX button in your form, a nice way of adding javascript is to use an IAjaxCallDecorator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
form.add(new AjaxButton("removeButton") {
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
private static final long serialVersionUID = 1L;
@Override
public CharSequence preDecorateScript(CharSequence script) {
return "if(!confirm('Are you sure you want to delete this?')) return false;" + script;
}
};
}
}