简体   繁体   English

模板化JSF 2.0 Primefaces

[英]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: 作为我的网站和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. 现在,如果我尝试将template =“ template.xhtml”更改为template.jsf,它就不会出现在任何地方...按现在的方式,我的“内容”页面将完全位于日蚀的页眉和页脚中间预览,但在浏览器上根本没有内容。

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 ? 我正在使用primefaces3.1.1,并且我有javax.faces-2.1.14 + jsf-api和jsf-impl,所以我认为它的primefaces 3和JSF 2是什么?

I think you are using facelets (templating) in a wrong way. 我认为您使用错误的方式(模板)。 You should'nt have html and body tags on your main page. 您的首页上不应包含html和body标签。 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). 必须在<ui:composition>标签中定义将使用模板的页面,并且模板应将页面定义为一个整体(html,body,head标签等)。

Example: 例:

index.html 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 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM