《wicket学习二十二》&PageDataViewExample

好久没有来更新关于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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值