It is a tool which provides the facility to implement the user interface. Templating is a useful Facelets feature that allows you to create a page that will act as the base for the other pages in an application. By using templates, you can reuse code and avoid recreating similarly pages again and again. Templating also helps in maintaining a standard look and feel in an application with a large number of pages.
The following table contains Facelets tags that are used for creating templates.
Creating Facelets Template
Creating template involves the following steps. Here, we are using Net Bean IDE to create the Facelets Template.
1) Creating new file.
2) Select JavaServer Faces and Facelets Template from categories and file types respectively.
3) Select CSS layout for the Facelets template file.
The Facelets tag library includes the main templating tag ui:insert. A template page which is created with this tag allows you to define a default structure for a page. We can use template page as a template for other pages.
The above template file is divided into four sections: a top section, a left section, a content section and a main section. We can further reuse this structure for the other pages of the application.
In index file, we have used png images to represent template layout. You can place your own images to execute this project.
ui:composition tag is used to implement template into the index.xhtml file.
ui:define tag is used to insert content into the implemented template.
// index page