如何使AjaxLazyLoadPanel的繁忙指示器居中

时间:2017-07-10 12:15:34

标签: ajax wicket-1.6

我有一个模式,可以连续显示3个不同的面板(与用户的选择一致)。

此模式的第二个面板是一个AjaxLazyLoadPanel,当它出现时,它左对齐而不是居中对齐,如下图所示。 Modal showing the busy indicator 1 如何将繁忙指示器居中?

enter image description here 以下是模态的类

 public class DetailsModal2 extends Modal<IModel<PaymentDomain>> {

  @SpringBean
  private IService service;

  private Component noButton;
  private Component yesButton;
  private Component noButton;
  private String paymentId;
  private Panel replacedPanel;
  private IModel<PaymentDomain> model;

  public DetailsModal2(String id, IModel<PaymentDomain> model, String party) 
  {
   super(id);
   this.party = party;
   this.model = model;
   this.paymentId = model.getObject().getPaymentGUID();

   replacedPanel = new AreYouSure("replacedPanel");
   replacedPanel = panel1;
   replacedPanel.setOutputMarkupId(true);
   add(replacedPanel);


   addButton(yesButton = new BootstrapAjaxLink<String>("button", null, Buttons.Type.Warning, new ResourceModel("details")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {

    addNewPanel(new AjaxLazyLoadPanel("replacedPanel") {
        @Override
        public Component getLazyLoadComponent(String markupId) {
            if (!condition)) {

                message = service.getPayment(paymentId);

                if (message == null) {
                    return new VotingResultPanel(markupId, true);
                } else 
                {
                    return new VotingResultPanel(markupId, false);
                }
            } // close if

            else if (condition)) {

                message = service.setPayment(paymentId);
                if (message == null) {
                    return new VotingResultPanel(markupId, true);

                } else {
                    System.out.println("" + message.getError());
                    return new VotingResultPanel(markupId, false);
                }
            }

            else {
                System.out.println("error");
            }
        }
    }, target);

    this.setOutputMarkupPlaceholderTag(true);
    this.setVisible(false);
    noButton.setOutputMarkupPlaceholderTag(true);
    noButton.setVisible(false);
    closeButton.setVisible(true);
    target.add(this, noButton, closeButton);
  }

  });

   noButton = new BootstrapAjaxLink<String>("button", null, Buttons.Type.Primary) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target){
    close(target);
}
}.setLabel(Model.of("No"));
addButton(noButton);

}

closeButton = new BootstrapAjaxLink<String>("button", null, 
Buttons.Type.Primary) {
    private static final long serialVersionUID = 1L;

    @Override
    public void onClick(AjaxRequestTarget target){
        addNewPanel(panel1,target);
        yesButton.setOutputMarkupId(true);
        yesButton.setVisible(true);
        noButton.setOutputMarkupId(true);
        noButton.setVisible(true);
        closeButton.setOutputMarkupId(true);
        closeButton.setOutputMarkupPlaceholderTag(true);
        closeButton.setVisible(false);
        target.add(yesButton,noButton,closeButton);
        close(target);

    }
}.setLabel(Model.of("Close"));
closeButton.setOutputMarkupPlaceholderTag(true);
closeButton.setVisible(false);
addButton(closeButton);
}


 public void addNewPanel(Panel addpanel, AjaxRequestTarget target) {
 Panel newPanel = null;
 newPanel = addpanel;
 newPanel.setOutputMarkupId(true);
 replacedPanel.replaceWith(newPanel);
 target.add(newPanel);
 replacedPanel = newPanel;
}
}// close class

1 个答案:

答案 0 :(得分:0)

查看方法AjaxLazyLoadPanel.getLoadingComponent(String)。这是创建繁忙指标的那个。

默认实现只是创建一个没有任何样式的img标记:

public Component getLoadingComponent(final String markupId)
{
    IRequestHandler handler = new ResourceReferenceRequestHandler(
        AbstractDefaultAjaxBehavior.INDICATOR);
    return new Label(markupId, "<img alt=\"Loading...\" src=\"" +
        RequestCycle.get().urlFor(handler) + "\"/>").setEscapeModelStrings(false);
}

您可以覆盖该方法,例如使用img标记包围div标记,该标记包含一些额外的CSS:

@Override
public Component getLoadingComponent(final String markupId)
{
    IRequestHandler handler = new ResourceReferenceRequestHandler(
        AbstractDefaultAjaxBehavior.INDICATOR);
    return new Label(markupId, "<div style=\"text-align: center\"><img alt=\"Loading...\" src=\"" +
        RequestCycle.get().urlFor(handler) + "\"/></div>").setEscapeModelStrings(false);
}

当然你还可以返回一个完全自定义的Wicket面板,它可以显示更复杂的繁忙指示器,包括文本,图形,颜色等。