Adding JavaScript Confirm Dialog to AjaxButton
If you have an AJAX button in your form, a nice way of adding javascript is to use an IAjaxCallDecorator
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;
}
};
}
}