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

发布于 2024-12-14 21:32:49 字数 1352 浏览 0 评论 0原文

我有一个面板,其中包含 ByteArrayResource、到 ByteArrayResource 的 ResourceLink 以及一个应该显示资源的相对 URL 的标签。 I 标签使用 link.urlFor(IResourceListener.INTERFACE) 获取其值。当我在页面上创建两个面板并使用链接在它们之间交换时,只有第一个添加的面板中的标签才会显示正确的 URL。

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

正如您所看到的,第二个面板缺少网址的“../wicket/”部分,为什么会发生这种情况以及如何修复它?

我的面板初始化:

  @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)));
  }

这是我将面板添加到我的页面的方式,以及替换面板的链接:

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;
  }
});

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. I The label gets its value using 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.

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?

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;
  }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-12-21 21:32:49

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

The second url is calculated against the currently showed page, and thus its relative url looks differently than the one produced against '/home'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文