repeater.html
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<title>repeat</title>
</head>
<body>
<div wicket:id="repeater">
<h3 wicket:id="title"></h3>
<ul>
<li wicket:id="childs"><div wicket:id="content"></div></li>
</ul>
</div>
</body>
</html>
repeater.java
package org.jtpd.wicket.repeater;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.list.PropertyListView;
public class repeater extends WebPage {
private static List<AccordionItem> items = new ArrayList<AccordionItem>();
static {
items.add(new AccordionItem("title 1", "content 11", "content 12", "content 13"));
items.add(new AccordionItem("title 2", "content 21"));
items.add(new AccordionItem("title 3", "content 31"));
}
public repeater() {
ListView<AccordionItem> view = new PropertyListView<AccordionItem>("repeater", items) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<AccordionItem> item) {
item.add(new Label("title"));
item.add(new PropertyListView<String>("childs") {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<String> item) {
item.add(new Label("content", item.getModel()));
}
});
}
};
add(view);
}
public static class AccordionItem {
private String title;
private List<String> childs;
public AccordionItem(String title, String... content) {
this.title = title;
this.childs = Arrays.asList(content);
}
}
}