как включить несколько страниц xhtml, которые расширяют один и тот же шаблон в сводную страницу xhtml,

Как мы можем включить несколько страниц xhtml в сводную страницу. Здесь все страницы xhtml, включая один и тот же шаблон.

общий шаблон.xhtml

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title> SNS </title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="sns.css" type="text/css" />
</head>
<h:body>

    <div id="header">
        <ui:insert name="commonHeader">
            <ui:include src="header.xhtml" />
        </ui:insert>
    </div>
    <div id="content">
        <ui:insert name="commonBodyContent">
            Common Body Content.
        </ui:insert>
    </div>
    <div id="footer">
        <ui:insert name="commonFooter">
            <ui:include src="footer.xhtml" />
        </ui:insert>
    </div>
</h:body>
</html>

updatePersonalDetails.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        .........;
        ..........;
    </ui:define>

</ui:composition>

обновленный адрес.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        .........;
        ..........;
    </ui:define>

</ui:composition>   

selectPreferences.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        .........;
        ..........;
    </ui:define>

</ui:composition>

резюме.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:include src="updatePersonalDetails.xhtml" />
    <ui:include src="updatedAddress.xhtml" />
    <ui:include src="selectPreferences.xhtml" />

</ui:composition>   

Какими бы ни были данные, которые у меня есть на всех страницах xhtml, они должны отображаться точно так же на сводной странице. Но включение этого приводит к отображению нескольких <html> документов на странице.

Как мы можем это решить?


person uday    schedule 27.12.2012    source источник


Ответы (1)


Переместите содержимое тела в другой шаблон, который вы также включите <ui:include> в клиентов шаблона.

E.g. updatePersonalDetails.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        <ui:include src="updatePersonalDetails-content.xhtml" />
    </ui:define>

</ui:composition>

(повторить и для остальных)

так что вы можете просто сделать это в summary.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        <ui:include src="updatePersonalDetails-content.xhtml" />
        <ui:include src="updatedAddress-content.xhtml" />
        <ui:include src="selectPreferences-content.xhtml" />
    </ui:define>

</ui:composition>   

Не связанные с конкретной проблемой, подумайте о том, чтобы поместить шаблоны и включения в папку /WEB-INF, чтобы предотвратить прямой доступ к ним. См. также ">Какие файлы XHTML нужно помещать в /WEB-INF, а какие нет?

person BalusC    schedule 27.12.2012
comment
Как бы поступили, если бы updatedAddress.xhtml, selectPreferences.xhtml и т. д. имели больше ui:define: в дополнение к commonBodyContent? Скажем, например, поле secTitle. Есть ли способ определить его в updatedAddress-content.xhtml и т. д. и использовать его как в updatedAddress.xhtml, так и в summary.xhtml? - person Lii; 06.11.2014
comment
Я думаю, что это то же самое, о чем спрашивают здесь . - person Lii; 06.11.2014