how to create a repeating list of links inside a li tag using apache wicket?

隐身守侯 提交于 2019-12-04 15:12:42

so after much testing this worked for me. HTML should look like:

<ul>
  <ui wicket:id="LinkList"><a wicket:id="Link"><span wicket:id="Text"/></a></ui>
</ul>

and then the repeating view code will be:

RepeatingView view = new RepeatingView("LinkList");

add(view);

WebMarkupContainer list = new WebMarkupContainer(view.newChildId());
ExternalLink externalLink = new ExternalLink("Link", "http://www.google.com");
externalLink.add(new Label("Text","Google"));
list.add(externalLink);

view.add(list);

You can use ListView to create a repeating list of links from code. A ListView is a repeater that makes it easy to display/work with Lists. A ListView holds ListItem children. Items can be re-ordered and deleted, either one at a time or many at a time.

Example:

<tbody>
   <tr wicket:id="rows" class="even">
     <td><span wicket:id="id">Test ID</span></td>
     ...

Though this example is about a HTML table, ListView is not at all limited to HTML tables. Any kind of list can be rendered using ListView.

The related Java code:

 add(new ListView<UserDetails>("rows", listData)
 {
    public void populateItem(final ListItem<UserDetails> item)
    {
            final UserDetails user = item.getModelObject();
            item.add(new Link("id", user.getId()));
    }
 });

Where listData contains the id of every link.

There are many choices in how to implement this sort of thing, but they all use some sort of repeater.

See wicket repeater examples for many examples of this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!