好久没有来更新关于wicket方面的内容了,最近一直忙,忙着去看cesium三维方面,计算机图形webgl方面的知识。今天有点空,来看一下这个东西。相关表格是各类网站中不可或缺的一个重要元素,在开发wicket相关的程序也是不例外的。那么今天我们来看一下wicket的表格。做成的效果如下图所示。
我们来看一下,在HomePage类中使用的到表格,主要看一下数据的构造。
public class HomePage extends WebPage {
public HomePage() {
List<String[]> countries = loadCountriesFromCsv();
ListDataProvider<String[]> listDataProvider =
new ListDataProvider<String[]>(countries);
DataView<String[]> dataView = new DataView<String[]>("rows", listDataProvider) {
@Override
protected void populateItem(Item<String[]> item) {
String[] countriesArr = item.getModelObject();
RepeatingView repeatingView = new RepeatingView("dataRow");
for (int i = 0; i < countriesArr.length; i++){
repeatingView.add(
new Label(repeatingView.newChildId(), countriesArr[i]));
}
item.add(repeatingView);
}
};
dataView.setItemsPerPage(15);
add(dataView);
add(new PagingNavigator("pagingNavigator", dataView));
}
private List<String[]> loadCountriesFromCsv() {
InputStream countriesStream = HomePage.class.getResourceAsStream("countries.csv");
Scanner scanner = new Scanner(countriesStream);
List<String[]> countries = new ArrayList<String[]>();
while(scanner.hasNext()){
String curLine = scanner.nextLine();
String[] countryData = curLine.split(";");
countries.add(countryData);
}
scanner.close();
return countries;
}
}
再来看一下,HomePage.html页面
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="utf-8" />
<title></title>
<wicket:head>
<style type="text/css">
table,th,td { border:1px solid black; padding: 3px; }
table { border-collapse:collapse; }
</style>
</wicket:head>
</head>
<body>
<p>Countries of the world</p>
<div wicket:id="pagingNavigator"></div>
<br />
<table>
<tr>
<th>ISO 3166-1</th>
<th>Name</th>
<th>Long name</th>
<th>Capital</th>
<th>Population</th>
</tr>
<tr wicket:id="rows">
<td wicket:id="dataRow"></td>
</tr>
</table>
</body>
</html>
web.xml配置过滤器。
<web-app>
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>wicket.AnnotationsRolesStrategyExample</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>demo.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.AnnotationsRolesStrategyExample</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>