简体   繁体   English

小门:无法在面板内获取正确的资源URL

[英]Wicket: Can't get correct Resource URL inside panels

I have a Panel containing a ByteArrayResource, ResourceLink to the ByteArrayResource and a Label that is supposed to display the relative URL to the resource. 我有一个面板,其中包含一个ByteArrayResource,指向ByteArrayResource的ResourceLink和一个应该显示资源相对URL的Label。 I The label gets its value using link.urlFor(IResourceListener.INTERFACE) . I标签使用link.urlFor(IResourceListener.INTERFACE)获得其值。 When I create two panels on my page and swap between them using a link, only the label in the panel that was added first will display the correct URL. 当我在页面上创建两个面板并使用链接在它们之间交换时,只有首先添加的面板中的标签会显示正确的URL。

Label from the first panel: ../wicket/page?0-IResourceListener-a_panel-lnk
Label from the second panel: page?1-IResourceListener-a_panel-lnk

As you can see the second panel is missing the '../wicket/' part of the url, why is this happening and how can i fix it? 如您所见,第二个面板缺少URL的'../wicket/'部分,为什么会发生这种情况,我该如何解决?

My panels onInitialize: 我的面板初始化:

  @Override
  protected void onInitialize() {
    super.onInitialize();
    csv = new ByteArrayResource("text/csv") {
      //Generate the CSV
      //...
    };

    //Create a link to the CSV resource
    ResourceLink<Void> link = new ResourceLink<Void>("lnk", csv);
    add(link);
    //Display the URL to the resource
    add(new Label("lbl", (String)link.urlFor(IResourceListener.INTERFACE)));
  }

This is how I add the panels to my page, and the link for replacing panels: 这是我将面板添加到页面中以及替换面板的链接的方式:

aPanel = new APanel("a_panel", resultsModel, false);
add(aPanel);
// Swap the panel
add(new Link<Void>("swap") {
  private static final long serialVersionUID = 1L;
  private Panel alt = new GraphPanel("a_panel", resultsModel, true);

  @Override
  public void onClick() {
    Panel tmp = aPanel;
    aPanel.replaceWith(alt);
    aPanel = alt;
    alt = tmp;
  }
});

第二个URL是针对当前显示的页面计算的,因此其相对URL看起来与针对“ / home”生成的相对URL不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM