Component ui: JSF composition does not work

0

I'm creating an example template but when the page opens it is blank, the template and page that tries to pull the template follows:

master-template.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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="titulo">Sistema de livraria on-line</ui:insert></title>
<h:outputStylesheet library="css" name="sistema.css" />
</h:head>
<h:body>
<div id="conteudo">
    <ui:insert name="corpo" />
</div>
</h:body>
<p:separator style="margin-top: 20px" />
<footer> Exemplo de Template - <a href="#" target="_blank">www.exemplo.com.br</a>

</html>

example.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/template/master-template.xhtml ">

<ui:define name="conteudo">Exemplo 2</ui:define>

</ui:composition>

And when the page opens it only displays "Example2" and looking at the source code it generated in the browser, it looks like this:

<html>
<head></head>
<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:f="http://xmlns.jcp.org/jsf/core" template="/WEB-INF/template/master-template.xhtml ">
<ui:define name="conteudo">Exemplo 2</ui:define>
</ui:composition>
</body>
</html>
    
asked by anonymous 15.10.2015 / 03:17

1 answer

3

In your main template , you have declared a div#conteudo HTML element and defined that JSF will render an area identified by the name corpo within that element, as can be verified in the master-template.xhtml file:

<div id="conteudo">
    <ui:insert name="corpo" />
</div>

However, when you use the template , you define ( ui: define ) an area identified by the name conteudo , be verified in your example.xhtml file:

<ui:define name="conteudo">Exemplo 2</ui:define>

At the time of rendering your page, JSF received an area identified by the name conteudo but received no instructions on how to render it.

I recommend reading the following material, which makes this explanation very clear: JSF 2 Templating with Facelets example

    
15.10.2015 / 04:25