Customizing IndicatingAjaxLink in wicket

社会主义新天地 提交于 2020-01-03 09:10:14

问题


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?


回答1:


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>



回答2:


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()


来源:https://stackoverflow.com/questions/11773885/customizing-indicatingajaxlink-in-wicket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!