模板不适用于jsf 1.2

时间:2013-09-03 05:10:58

标签: jsf-1.2

我遇到了jsf 1.2的问题,尤其是模板加载问题。 我的web.xml打开index.xhtml。

(的index.xhtml)

<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:c="http://java.sun.com/jstl/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="template.xhtml">

    <ui:define name="content">
        <h1>H1 index</h1>
    </ui:define>
</ui:composition>

(的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:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
<head>
<title>Titolo</title>
</head>
<body>
    <ui:include src="header.xhtml" />

    <ui:insert name="content" />

</body>
</html>

(header.xhtml)

<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:c="http://java.sun.com/jstl/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

<h:outputText value="This is the header 23456"/>

</ui:composition>

当我运行我的应用程序时,我只看到“H1索引”。我没有看到“这是标题23456”,我看不到标题。为什么呢?

提前感谢所有人。

1 个答案:

答案 0 :(得分:0)

您也必须在header.html中使用<u:define name="header">,就像在index.html中使用<u:define name="content">一样。如果您想在不定义每个部分的情况下在模板中插入“其他内容”,只需在模板中使用<u:insert />即可。这会将每个未定义的块插入到模板中。