问题
I am new with Wicket framework, so I don't know if this is possible. I want that when I click on submit button of form (in Java it's AjaxButton) javascript confirmation dialog pops up, but when I click No, it always calls method onSubmit of this button. What am I doing wrong?
Here my code:
AjaxButton submit;
add(submit = new AjaxButton("ajaxSubmitProduct"){
private static final long serialVersionUID = 1L;
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
tag.put("onclick", "return confirm('Yes or No?');");
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
target.add(form);
Product p = (Product) form.getModelObject();
DBBroker.save_product(p);
success("You have sucessfully added a new product.");
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
target.add(form);
}
});
回答1:
You should use an Ajax precondition:
https://cwiki.apache.org/confluence/display/WICKET/Getting+user+confirmation
回答2:
Or use a ModalWindow
, if you don't like the Javascript confirm()
look-and-feel (and who does? ;)
See for example here:
http://mysticcoders.com/blog/wicket-ajax-confirmation-modal-window/
来源:https://stackoverflow.com/questions/27064873/wicket-ajaxbutton-and-javascript-condition