clickを使ってみる 8

Table control

tableに表示されるデータは、TableコントロールのsetRowList()メソッドにListで渡す。Listの各要素が行に対応するが、行の内容(各カラム値)は、カラム名をキーとするMapで作成すればよい。たとえば以下のようになる。

public class HomePage extends Page {
    public HomePage() {
        table.setClass("simple");
        table.setPageSize(4);
        table.addColumn(new Column("email"));
        table.addColumn(new Column("age"));
        table.addColumn(new Column("holdings"));
    }
    
    public void onRender() {
        List customer = new ArrayList(10);
        Map row = new HashMap();
        row.put("id", "123456");
        row.put("name", "Your Name");
        row.put("email", "xxx@mail.company.com");
        row.put("age", new Integer(32));
        row.put("holdings", new Integer(1000000));
        customer.add(row);
        table.setRowList(customer);
    }

    public String getContentType() {
        return "text/html; charset=Windows-31J";
    }
}

また、Tableのスタイルは、上の例のようにsetClass()メソッドでクラス名を指定しておこなうが、付属のテーブル用のスタイルシートを使うときは、マニュアルにあるとおり、PageImportをつかって、対応するHTMLを以下のようにする。

<html>
<head>
  $imports
</head>
  $table
</body>
</html>