Vitor Hugo
Vitor Hugo

Reputation: 1126

templating JSF 2.0 Primefaces

So I have:

<!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: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">

<h:body>
    <ui:composition template="template.xhtml">
        <ui:define name="content">
            <h:outputText value="Test!!!" />
        </ui:define>
    </ui:composition>
</h:body>
</html>

as my main page on my website and on template.xhtml:

<div id="content">
     <h:panelGroup layout="block" styleClass="centercss">  
    <ui:insert name="content" />
 </h:panelGroup>
</div>

...in the middle of the footer and the header views.

Now if I try to change the template="template.xhtml" to template.jsf it does not appear anywhere... the way it is right now I get my 'content' page perfectly in the middle of header and footer on the eclipse preview, but on the browser there's no content at all.

Im using primefaces3.1.1 and I have javax.faces-2.1.14 + jsf-api and jsf-impl, so I think its primefaces 3 and JSF 2. What is the problem here ?

Upvotes: 0

Views: 615

Answers (1)

dgimenes
dgimenes

Reputation: 912

I think you are using facelets (templating) in a wrong way. You should'nt have html and body tags on your main page. The page that will use the template must be defined in a <ui:composition> tag, and the template shall define the page as a whole (html, body, head tags, etc).

Example:

index.html

<?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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
    template="template.xhtml">
    <ui:define name="content">
        <h:outputText value="Test!!!" />
    </ui:define>
</ui:composition>

template.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:body>
    <div id="content">
        <h:panelGroup layout="block" style="background-color: red;">
            <ui:insert name="content" />
        </h:panelGroup>
    </div>
</h:body>
</html>

Upvotes: 1

Related Questions