This is another article which is showing about how to define a title of the JSF file. Specifically, it is the title exist in the header of the JSF file. So, this is a JSF file exist in a Java web application. This JSF file does not use another specific JSF framework such as Primefaces. In other words, it is using a pure JSF file. But instead of using the standard HTML tag, it will use an additional JSF tag. In this case, it is using an ui tag from the JSF library itself. Before moving on to the script, there is several things which is nice for knowing. The first one is about the Java web application itself. It is getting the setting from the previous article. It is an article with the title of ‘How to Create maven-based Web Application in NetBeans IDE’ in this link. The second one, it is not only a normal Java web application, but it uses JSF framework. For reference, the step exist also in the previous article. That article available exist in this link with the title of ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’.
Define Title of the JSF File Header using ui Tag
Without further explanation, the following is the steps to achieve that :
First of all, just access the Web Pages folder which is part of the Java web application.
Then, in the Web Pages folder, create a new XHTML file. In this case, just give it with the name ‘index-with-template.xhtml’ for an example.
Next, fill the file ‘index-with-template.xhtml’ with the following content :
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title> <ui:insert name="title">Default Title</ui:insert> </title> </h:head> </html>
Build, compile and run the Java web application. In this case, the process is using NetBeans IDE. If the process is a success, the following is the appearance of the output :