Wicket AjaxButton and javascript condition

有些话、适合烂在心里 提交于 2019-12-13 19:12:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!