Holm
Holm

Reputation: 982

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

Upvotes: 0

Views: 463

Answers (1)

martin-g
martin-g

Reputation: 17503

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

Upvotes: 1

Related Questions