Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing IndicatingAjaxLink in wicket

Tags:

java

wicket

in my current project i've faced a problem of customizing IndicatingAjaxLink in wicket, is there any solution to change standart gif image to my own? For example we have following listeneer

   add(new IndicatingAjaxLink("closeReceivedBillspanel") {
            public void onClick(AjaxRequestTarget art) {
                  // some timeconsuming calculations
           }
   });

as user clicks this link, the gif with loading appears, and i want to change this gif, is there any solution for this problem?

like image 926
ilya.stmn Avatar asked Aug 02 '12 08:08

ilya.stmn


2 Answers

Have your page implements the IAjaxIndicatorAware interface

public class BasePage extends WebPage implements IAjaxIndicatorAware {   

 public BasePage(final PageParameters parameters) {
    // Home link
    AjaxLink<Page> homeLink = new AjaxLink<Page>("homeLink") {
      private static final long serialVersionUID = 1L;

      @Override
      public void onClick(AjaxRequestTarget target) {
        setResponsePage(HomePage.class);
      }
    };
    add(homeLink);
  }

  @Override
  public String getAjaxIndicatorMarkupId() {
    return "indicator";
  }

This way, you can set, in the html, any image you want to display when the loading appears by changing the image in the "img" tag

<div id="indicator" style="display: none;">
 <div class="indicator-content">
  Please wait... <wicket:link><img src="images/loading.gif" width="16" height="16" alt="loading" /></wicket:link>
 </div>
</div>
like image 76
jrochette Avatar answered Sep 19 '22 22:09

jrochette


Create yoru own custom class like, (copy whats inside IndicatingAjaxLink and update)

   public class MyIndicatingAjaxLink<T> extends AjaxLink<T> implements IAjaxIndicatorAware {
         private final MyAjaxIndicatorAppender indicatorAppender = new MyAjaxIndicatorAppender();    
    .
    //rest of the code is same as IndicatingAjaxLink class
    .
    }

Also you need a custom AjaxIndicatorAppender within your customIndicatingAjaxLink and you need to override below method of indicatorAppender to return path of your custom image

protected CharSequence getIndicatorUrl()
like image 28
fmucar Avatar answered Sep 19 '22 22:09

fmucar