Wicket:无法在面板内获取正确的资源 URL
我有一个面板,其中包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二个 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'.