[英]How to update a Wicket-Listview with an AjaxLink?
i want to update my ListView with NewsEntries via an Ajax-Link. 我想通过Ajax-Link用NewsEntries更新ListView。 I have a link for each month and on click, i want to show the news from the specific month. 我每个月都有一个链接,点击后,我想显示特定月份的新闻。
I tried this tutorial but it does not work: http://blog.xebia.com/2008/06/04/wicket-updating-listviews-using-an-ajaxlink/ 我尝试了本教程,但没有用: http : //blog.xebia.com/2008/06/04/wicket-updating-listviews-using-an-ajaxlink/
Here is a sample of my code: 这是我的代码示例:
add(new Label("title", "News Archive"));
List<NewsEntry> newsEntries = new ArrayList<NewsEntry>();
final ListView<NewsEntry> listview = new ListView<NewsEntry>(
"newsItem", newsEntries)
{
private static final long serialVersionUID = -4294698878214798680L;
@Override
protected void populateItem(final ListItem<NewsEntry> item)
{
Link<Void> link = new Link<Void>("newsItemLinkID")
{
private static final long serialVersionUID = 6176760893378172041L;
@Override
public void onClick()
{
setResponsePage(getPage());
}
};
link.add(new Label("newsItemLinkName", item.getModelObject()
.getHeadline()));
link.setOutputMarkupId(true);
item.add(link);
}
};
listview.setOutputMarkupId(true);
add(listview);
add(new AjaxLink<Object>("march")
{
private static final long serialVersionUID = 974013580329804810L;
@Override
public void onClick(AjaxRequestTarget target)
{
NewsDAO news = new NewsDAO();
listview.setList(news.getNewsFromMonth(MONTH.MARCH));
target.addChildren(listview, Link.class);
}
});
At the moment, nothing will be displayed. 目前,没有任何显示。 I got no error, neither in the ajax-debug window, nor in the my eclipse console. 无论是在ajax-debug窗口中,还是在我的eclipse控制台中,我都没有错误。 I'm kinda stuck right now and don't know whats been wrong. 我现在被困住了,不知道出了什么问题。
You should wrap your ListView into a WebMarkupContainer and update this Container instead of the ListView. 您应该将ListView包装到WebMarkupContainer中,并更新此Container而不是ListView。
WebMarkupContainer wmc = new WebMarkupContainer("listWmc");
add(wmc);
// init your listView
// ...
wmc.add(listView);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.