lazydaemon
lazydaemon

Reputation: 2509

How to update a Wicket-Listview with an AjaxLink?

i want to update my ListView with NewsEntries via an Ajax-Link. 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/

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. I'm kinda stuck right now and don't know whats been wrong.

Upvotes: 0

Views: 5600

Answers (1)

magomi
magomi

Reputation: 6685

You should wrap your ListView into a WebMarkupContainer and update this Container instead of the ListView.

WebMarkupContainer wmc = new WebMarkupContainer("listWmc");
add(wmc);

// init your listView
// ...

wmc.add(listView);

Upvotes: 7

Related Questions