Introduction
This is an article where the main focus is just to define a header for a JSF file. Actually, it is in a Java web application which has a JSF and also Primefaces framework as part of it. The setting for this Java web application is available from other previous articles. The first article exist in this link which is focusing on how to create a maven-based Java web application. That article has the title of’How to Create maven-based Web Application in NetBeans IDE’. And the second article is informing how to add JSF library in the Java web application exist in this link. That is an article with the title of ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’. Then, there is the third article with the title of ‘How to Add Primefaces Library to a maven-based Java Web Application in NetBeans IDE’ in this link.
Define Header of a JSF File in Java Web Application
Following the above part, this part is focusing on to define header in a JSF file. That JSF file itself is part of the Java web application. Actually, this article is the continuation from the previous article in this link. There is a specific useful information in that previous article which has the title of ‘How to Solve Error Message XML Parsing Error: prefix not bound to a namespace when running Java Web Application using Primefaces Framework’. That specific part of information is a script exist as follows :
<?xml version="1.0" encoding="UTF-8"?> <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"> </ui:composition>
In order to define a header, just add the following part inside the above script. Those part or snippet code is available as follows :
<ui:define name="head"> <title>Admin Starter</title> </ui:define>
Overall, after the revision, the script will be in the following appearance :
<?xml version="1.0" encoding="UTF-8"?> <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"> <ui:define name="head"> <title>Admin Starter</title> </ui:define> </ui:composition>
The above script is actually going to end in a failure for rendering the header part. Actually, there is also an additional information about how to solve that header part which is not appearing yet. It exist in the article with the title of ‘How to Solve Error HTML Parsing is not working in a JSF file of Java Web Application running using Primefaces Framework’ in this link. According to that articlem, the revision for the script so that it will render the header part perfectly is by adding a specific script. That specific script is a ‘namespace’ for HTML definition as ‘xmlns=:http://www.w3.org/1999/xhtml”‘. So , overall the script will be as in the following appearance :
<?xml version="1.0" encoding="UTF-8"?> <ui:composition xmlns=:http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"> <ui:define name="head"> <title>Admin Starter</title> </ui:define> </ui:composition>
The above script output exist as in the following image :