title: Wicket Call Javascript Function Inside AjaxRequestTarget
body: <p>I have a web application that uses Wicket. My problem is the following:
  I have a part of code that runs inside an AjaxRequestTarget that spend a long time, and I have the necessity to show during this operation a busy indicator, in order to show to the user that we are trying to process the request.</p>
  
  <p>I try to use target.appendJavascript("jsfunction()") but it doesn't work, because it is fired after the execution of the method. How can I accomplish this goal?</p>
  
  <p>My example code is the following</p>
  
  <pre><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);
              }}}
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The solution provided by martin-g works fine with AjaxLink, but my problem is more complex. I have a ConfirmModal that extends ModalWindo, with this implementation
  public abstract class ConfirmModalPanel extends Panel {</p>
  
  <pre><code>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
  );
  </code></pre>
  
  <p>}</p>
  
  <p>The functions "start()" and "finish()" are called correctly, but the execution of the request write inside the onClickOK method continue, and I cannot show the busy indicator. </p>