How to correctly use templates with jsf and primefaces

0

I made a template and called it inside another page, but what I apply on the second page does not work. In index.xhtml I write a sentence to test, but it does not print on the screen. Only the template is rendered.

I'm using a maven project with primeface 6.0 and jsf 2.2.16.

// template.xhtml


      xmlns: h="http://java.sun.com/jsf/html"
    xmlns: f="http://java.sun.com/jsf/core"
    xmlns: p="http://primefaces.org/ui"
    xmlns: ui="http://java.sun.com/jsf/facelets" >

<h:head>  
<title>PROJETO MUSICANDO</title>  
</h:head>  

<h:body>  

</h:body>  
</html>  

//index.xhtml  

<?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:f="http://java.sun.com/jsf/core"  
xmlns:p="http://primefaces.org/ui"  
xmlns:ui="http://java.sun.com/jsf/facelets">  

<!-- importa o template -->  
<ui:composition template="/template.xhtml"/>  

<!-- essa frase não aparece quando digito localhost:8080/webmusicos/faces/index.xhtml -->   
<h:outputText value="Bem-vindo ao projeto musicando"/>  


</html>  
    
asked by anonymous 25.05.2018 / 01:01

1 answer

0

The content on the index page must be inside the composition tag.

// template.xhtml


      xmlns: h="http://java.sun.com/jsf/html"
    xmlns: f="http://java.sun.com/jsf/core"
    xmlns: p="http://primefaces.org/ui"
    xmlns: ui="http://java.sun.com/jsf/facelets" >

<h:head>  
<title>PROJETO MUSICANDO</title>  
</h:head>  

<h:body>  

</h:body>  
</html>  

//index.xhtml  

<?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:f="http://java.sun.com/jsf/core"  
xmlns:p="http://primefaces.org/ui"  
xmlns:ui="http://java.sun.com/jsf/facelets">  

<!-- importa o template -->  
<ui:composition template="/template.xhtml">  

<h:outputText value="Bem-vindo ao projeto musicando"/>  

</ui:composition>

</html>  
    
27.05.2018 / 18:13