0

我对 jsf 1.2 有疑问,尤其是在模板加载方面。我的 web.xml 打开 index.xhtml。

(索引.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>

(模板.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”,也没有看到标题。为什么?

提前感谢大家。

4

1 回答 1

0

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

于 2013-09-03T06:58:45.317 回答