Search code examples
jsfjsf-2primefacesfacelets

ui:insert is not rendering in the main template


After a year gap i have again started working in JSF and facing problem in the facelets usage Below is the maintemplate.xhtml

<!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" /></title>
  </h:head>
   <ui:insert name="header" /> 
    <body>

     content
    </body>
</html>

Below is the ui:composition of the other xhtml file

enter code here
<?xml version="1.0" encoding="UTF-8" ?>
  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui"
            template="/index.xhtml">


    <ui:define name="title"><h:outputText value="Please Sign In" /></ui:define>
    <ui:define name="header"><h:outputText value="Please Sign In" /></ui:define>
  </ui:composition>

the same content works with the ui:include but doesn't work with the ui:defin and ui:insert combination


Solution

  • I was using the tags in the wrong way need to include include tag inside the insert to get the correct template functionality