簡體   English   中英

如何在AjaxLink(Wicket)的onSubmit方法中調用Ajaxdecorator或javascript

[英]How to call Ajaxdecorator or javascript in onSubmit method of AjaxLink (Wicket)

public class engageLink extends AjaxLink{
    private Engage engage;
    private String name;

    engageLink(String string, Engage anEngage,String name) {
        super(string);
        this.engage = anEngage;
        this.name = name;
        hasEngage=((Application) getApplication()).getVtb().hasEngagement(engage,name);
        if(hasEngage)
            this.add(new AttributeAppender("onclick", new Model("alert('This is my JS script');"), ";"));
    }
    boolean randevuAlmis;


    @Override
    public void onClick(AjaxRequestTarget target) {

         if(hasEngage){
              //do nothing or call ajax on failure script
         } else{
                 ((Application) getApplication()).getVtb().addEngagement(engage, name);
         }
         setResponsePage(new Sick(name));
    }
        @Override
            protected org.apache.wicket.ajax.IAjaxCallDecorator getAjaxCallDecorator()
            {
                return new AjaxCallDecorator()
                {
                    @Override
                    public CharSequence decorateOnSuccessScript(CharSequence script)
                    {
                        return "alert('Success');";
                    }

                    @Override
                    public CharSequence decorateOnFailureScript(CharSequence script)
                    {
                        return "alert('Failure');";
                    }



                };
            };
}

這是我的代碼。在單擊方法中,我將調用ajax onfailure腳本。但它不起作用。

我嘗試在構造函數中添加javascript。它也不起作用。

問題是什么。

注意,我稱ajaxdecorator之類的;

getAjaxCallDecorator().decorateOnFailureScript("some message");

我該如何解決這些問題。

謝謝

您是否正在嘗試成功調用失敗腳本? 如果是這樣,您可以致電:

target.appendJavascript("alert('Failure');");

要么

target.appendJavascript(getAjaxCallDecorator().decorateOnFailureScript("some message"));

但是,您要在onClick()方法末尾調用setResponsePage(),我認為這可能會阻止任何腳本的執行,因為您將重定向到另一個頁面,而不是簡單地執行ajax響應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM