One advantage of Facelet is its ability to easily set up a template. Easily, yes but not really the first time. After several Google searches, I do not find a complete tutorial that include all the steps to create a facelet template for ICEfaces. That the reason it takes me my afternoon to realize that I wanted.
For PHP developers, the concept is exactly the same and based on include tag and CSS styles.
Here are the steps :
- Create the layout. With Netbeans, there is the possibility to choose the type of template by adding a ICEfaces Facelet Template and the CSS is created automatically by the IDE !
In this example, we will create a xhtml page for the menu, the top and the bottom div will not be treated because we can imagine to put an image or a static text. As you can see, the content div only contains an insert tag but no include. The reason is that we want to use a dynamic content. - Create the menu.xhtml
You can see there is no HTML or BODY tag and but an <ui:composition> which contains the template name and also the declarations.
As we use JSF2, there is not necessary to declare the navigation rule in the faces-config.xml, the just need to enter the name of the page. There is also the possibility to create a dynamic menu with managed-bean. - Finally the content page
The define tag allows the inclusion of content page in the template. The code is inside the <ui:composition> tag, like the menu
I hope this mini tutorial will be usefull and understandable 🙂