I am facing an issue with my web application built using Wicket framework. The problem arises when a part of my code runs within an AjaxRequestTarget for a long duration, and I need to display a busy indicator to inform the user about the ongoing process.
My attempt to use `target.appendJavascript("jsfunction()")` did not yield the desired result as it executes after the method's completion. How can I successfully implement this functionality?
Here is an example snippet of my code:
final ConfirmModal del_modal = new ConfirmModal("del-btn", "Are you sure?") {
@Override
public void onClickOK(AjaxRequestTarget target) {
target.appendJavaScript("loadingFormFromTarget();");
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Logger.getLogger(ListPricePlanPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
UPDATE
A solution provided by martin-g worked well with AjaxLink, but my scenario is more complex. I have a ConfirmModal that extends ModalWindow with the following implementation:
public abstract class ConfirmModalPanel extends Panel {
public ConfirmModalPanel(String id, String text) {
super(id);
add(new Label("text", text));
AjaxLink ok = new AjaxLink("ok") {
@Override
public void onClick(AjaxRequestTarget target) {
onClikOK(target);
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new AjaxCallListener().onBeforeSend("start();").onComplete("finish();"));
}
};
add(ok);
add(new AjaxLink("ko") {
@Override
public void onClick(AjaxRequestTarget target) {
onClikKO(target);
}
});
}
abstract public void onClikOK(AjaxRequestTarget target);
abstract public void onClikKO(AjaxRequestTarget target);
}
The functions "start()" and "finish()" are triggered correctly, however, the execution of the request inside the `onClickOK` method continues without showing the busy indicator.