/** {@inheritDoc} */
  @Override
  protected void preparePaintComponent(final Request request) {
    super.preparePaintComponent(request);

    if (Cache.getCache().get(DATA_KEY) != null) {
      poller.disablePoll();
    }
  }
  /** Fakes a service call, using the WorkManager for threading. */
  private void fakeServiceCall() {
    poller.enablePoll();
    Cache.getCache().invalidate(DATA_KEY);

    new Thread() {
      @Override
      public void run() {
        try {
          Thread.sleep(SERVICE_TIME);
          Cache.getCache().put(DATA_KEY, "SUCCESS!");
        } catch (InterruptedException e) {
          LOG.error("Timed out calling service", e);
          Cache.getCache().put(DATA_KEY, "Timed out!");
        }
      }
    }.start();
  }
  /** Creates a AjaxPollingWButtonExample. */
  public AjaxPollingWButtonExample() {
    setLayout(new FlowLayout(Alignment.VERTICAL, 0, 5));

    WButton pollBtn = new WButton("Invoke service");
    add(pollBtn);

    WAjaxControl ajaxControl = new WAjaxControl(pollBtn, poller);
    poller.add(myDataComponent);
    myDataComponent.setVisible(false);

    add(poller);

    pollBtn.setAction(
        new Action() {
          @Override
          public void execute(final ActionEvent event) {
            myDataComponent.setVisible(true);
            fakeServiceCall();
          }
        });

    // make the image change an ajax request
    add(ajaxControl);
  }