tjtjtjのメモ

自分のためのメモです

guestbook#2

guestbook#1 で保存した値を読み出し、ページに表示する。

エントリリスト取得メソッドをサービスに追加

.service.GuestbookService.Java

    public List<Entry> getEntries() {
        EntryMeta meta = new EntryMeta();
        return Datastore.query(meta).asList();
    }

エントリリストを取得

.controller.guestbook.IndexController.Java

    public Navigation run() throws Exception {
        GuestbookService service = new GuestbookService();
        service.entry(new RequestMap(request));
        requestScope("entries", service.getEntries());
        return forward("index.jsp");
    }

エントリリストを表示

war/guestbook/index.jsp

<body>
<p>入力してください</p>
<form method="post" action="">
<textarea name="content"></textarea><br />
<input type="submit" value="submit"/>
</body>
<hr />
<c:forEach var="e" items="${entries}">
${f:h(e.content)}
<hr />
</c:forEach>
</body>