レイアウト機能実装されたそうです。
個人的にとても嬉しいです。これでやっと、本格的にいじり倒すことができそうです。
特徴をまとめると、(ほぼ、ひがさんのブログのコピーですが…)
- view/layout/layout.html が存在すれば、自動的に他のviewにそのレイアウトが適用される。
- 特にレイアウトを適用したくないviewに関しては、そのviewのPageクラスにgetLayout()メソッドを追加し、return null;
- 別のレイアウトファイル(例えばview/layout/layout2.html)を適用させたければ、getLayout()メソッドにて return "
view/layout/layout2.html"; - レイアウトファイル中では、teネームスペースを定義(下記 #1)
- te:includeタグで、別のファイルのbody要素の中身が取り込まれる(下記 #2 に例)
- te:includeChildBodyタグで、レイアウト呼び出し元ファイルのbody要素の中身が取り込まれる(下記 #3 に例)
#1
<html xmlns:te="http://www.seasar.org/teeda/extension">
#2
<te:include te:src="/layout/header.html"/>
#3
<te:includeChildBody/>
ところで、呼び出し元ファイルから、複数の要素をテンプレートに埋め込むことはできないのでしょうか。
例えば以下のような…。
呼び出し元ファイル
(前略) <span id="data1">AAAAA</span> <span id="data2">BBBBB</span> (後略)
レイアウトファイル
(前略) <te:include te:src="/layout/header.html"/> <table> <tr><td><te:includeChild te:id="data1"/></td> <td><te:includeChild te:id="data2"/></td></tr> </table> <te:include te:src="/layout/footer.html"/> (後略)
結果
(前略) (header.htmlの内容) <table> <tr><td>AAAAA</td> <td>BBBBB</td></tr> </table> (footer.htmlの内容) (後略)