Подтвердить что ты не робот

Как изменить элементы головы страницы при использовании ui: composition

Я хочу задать вопрос, что у меня есть шаблон-шаблон, подобный этому

<?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:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>Login</title>
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include src="header.xhtml" id="header"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content"></ui:insert>
            </div>
        </div>
        <div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
            <ui:insert name="bottom">
                <ui:include src="footer.xhtml" id="footer"/>
            </ui:insert>
        </div>
    </h:body>
</html>

На каждой моей странице я использую что-то вроде этого

<?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:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>City Setup</title>
    </h:head>

    <h:body>
        <ui:composition template="./WEB-INF/templates/layout.xhtml">
            <ui:define name="content">
                <h:form id="cityReviewform">
                    ......
                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</html>

Теперь, что происходит из-за композиции ui;, мой атрибут tile теперь работает на каждой странице, потому что ui: состав отбрасывает каждый тег за его пределами. Теперь на каждой странице у меня есть заголовок Login (например, основного шаблона). Поэтому я хочу спросить, как я могу сделать это, чтобы на каждой странице отображался собственный заголовок вместо Login (master tempalte title)?

Спасибо

4b9b3361

Ответ 1

В клиенте шаблона все <ui:composition> игнорируется. Вам нужно изменить подход к шаблону, чтобы предоставить <ui:insert> для заголовка в главном шаблоне, чтобы его можно было определить <ui:define> в клиенте шаблона.

Мастер-шаблон:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title><ui:insert name="title">Login</ui:insert></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include id="header" src="header.xhtml"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content" />
            </div>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">
                <ui:include id="footer" src="footer.xhtml" />
            </ui:insert>
        </div>
    </h:body>
</html>

Клиент шаблона:

<ui:composition template="/WEB-INF/templates/layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="title">City Setup</ui:define>

    <ui:define name="content">
        <h:form id="cityReviewform">
            ...
        </h:form>
    </ui:define>
</ui:composition>

См. также: