Jsf-templates-tag
提供:Dev Guides
JSF-テンプレートタグ
Webアプリケーションのテンプレートは、共通のインターフェースレイアウトとスタイルを定義します。 たとえば、同じバナー、共通ヘッダーのロゴ、フッターの著作権情報。 JSFは、標準のWebインターフェースレイアウトを提供するために、次のfaceletタグを提供します。
S.No | Tag & Description |
---|---|
1 |
ui:insert テンプレートファイルで使用されます。 テンプレートに配置されるコンテンツを定義します。 ui:defineタグはその内容を置き換えることができます。 |
2 |
ui:define テンプレートに挿入されるコンテンツを定義します。 |
3 |
ui:include 1つのxhtmlページのコンテンツを別のxhtmlページに含めます。 |
4 |
ui:composition
|
テンプレートを作成する
Webアプリケーション用のテンプレートの作成は、段階的な手順です。 以下は、サンプルテンプレートを作成する手順です。
ステップ1:ヘッダーファイルの作成:header.xhtml
ステップ3:コンテンツファイルの作成:contents.xhtml
ステップ4:テンプレートを作成する:common.xhtml
ステップ5a:デフォルトのコンテンツでテンプレートを使用:home.xhtml
common.xhtml、任意のxhtmlページで ui:composition タグを使用するテンプレートをロードします。
ステップ5b:テンプレートを使用して、独自のコンテンツを設定します:home.xhtml
common.xhtml、任意のxhtmlページで ui:composition タグを使用するテンプレートをロードします。 ui:define タグを使用して、デフォルト値をオーバーライドします。
応用例
テストJSFアプリケーションを作成して、JSFのテンプレートタグをテストしましょう。
Step | Description |
---|---|
1 | Create a project with a name helloworld under a package com.finddevguides.test as explained in the JSF - First Application chapter. |
2 | Create templates folder under src → main → webapp folder. |
3 | Create header.xhtml, footer.xhtml, contents.xhtml and common.xhtml files under src → main → webapp → templates folder. Modify them as explained below. |
4 | Create page1.xhtml and page2.xhtml files under src → main → webapp folder. Modify them as explained below. |
5 | Modify home.xhtml as explained below. Keep rest of the files unchanged. |
6 | Compile and run the application to make sure business logic is working as per the requirements. |
7 | Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver. |
8 | Launch your web application using appropriate URL as explained below in the last step. |
header.xhtml
contents.xhtml
common.xhtml
page1.xhtml
page2.xhtml
home.xhtml
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。
または、 Page2 リンクをクリックすると、次の結果が表示されます。