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');";
}
};
};
}
This is my code.IN the method on click i call ajax onfailure script .but it doesn't work.
I tried adding javascript in the constructor.It does not work too.
What is the problem.
Note i call ajaxdecorator like;
getAjaxCallDecorator().decorateOnFailureScript("some message");
How can i solve these problems.
Thanks
Are you trying to call the failure script without a failure? If that's the case, you could call:
target.appendJavascript("alert('Failure');");
or
target.appendJavascript(getAjaxCallDecorator().decorateOnFailureScript("some message"));
BUT, you are calling setResponsePage() at the end of the onClick() method, I think that could block any scripts from being executed, since you are redirecting to another page instead of simply executing the ajax response.
精彩评论