简体   繁体   中英

Template not working on jsf 1.2

I have a problem with jsf 1.2, in particular with the template loading. My web.xml open 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>

When I run my application I see only "H1 index". I don't see "This is the header 23456" and I don't see title. Why?

Thanks to all in advance.

you have to use <u:define name="header"> in your header.html too, just as you did in your index.html with <u:define name="content"> . If you want to insert "anything else" into template without defining every section, just use <u:insert /> in your template. This will insert every undefined block into your template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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