サーチ…
備考
JSFには、 faceletsタグと呼ばれるWebアプリケーションの共通レイアウトを作成するための特別なタグが用意されています。これらのタグは、複数のページの共通部分を1か所で管理するための柔軟性を提供します。
名前空間:
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
テンプレートを作成する方法
1つのアプリケーションのテンプレートを設定する
/WEB-INFフォルダの下にtemplate.xhtmlという名前のファイルを作成します。テンプレートファイルにはフレームワークのみがアクセスできるようにします。
/WEB-INF/template.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title><ui:define name="title">Default title</ui:define></title>
</h:head>
<h:body>
<!-- Some styles that we might include for our whole application -->
<h:outputStylesheet name="css/template.css" />
<!-- Shared content for the application, e.g. a header, this can be an include -->
<div>
Application Header
</div>
<!-- The content we want to define in our template client -->
<div>
<ui:insert name="content" />
</div>
</h:body>
</html>
このファイルは、アプリケーションのテンプレートとして機能します。ここで、viewディレクトリに特定のビューを定義します。
/home.xhtml
<ui:composition template="/WEB-INF/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="title">Home</ui:define>
<ui:define name="content">
Welcome to the application!
</ui:define>
</ui:composition>
このクライアント・ビューのtemplate属性を見てtemplate 。これは、JSFに必要なテンプレートを使用するように指示します。次に、 <ui:define>を使用して、テンプレート内で指定された場所に挿入される特定のコンテンツを定義します。クライアントで/home.xhtmlにアクセスすると、結果全体がレンダリングされます。
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow