Ivan
Ivan

Reputation: 65

Wicket AjaxButton and javascript condition

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);
    }

});    

Upvotes: 2

Views: 2631

Answers (2)

Rob Audenaerde
Rob Audenaerde

Reputation: 20099

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/

Upvotes: 0

svenmeier
svenmeier

Reputation: 5681

You should use an Ajax precondition:

https://cwiki.apache.org/confluence/display/WICKET/Getting+user+confirmation

Upvotes: 2

Related Questions