how to include multiple xhtml pages, which are extending same template into a summary xhtml page,
Asked Answered
R

1

8

How can we include multiple xhtml pages into a summary page. Here all the xhtml pages including same template.

commonTemplate.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>

updatedAddress.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>

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">

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

</ui:composition>   

Whatever the data i have in all xhtml pages, supposed to display exactly same in summary page. But including this causes multiple <html> documents to render on page.

How can we solve this ?

Reinareinald answered 27/12, 2012 at 12:33 Comment(0)
B
7

Move the body content into another template which you include by <ui:include> in the template clients as well.

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>

(repeat for the others as well)

so that you can just do this in 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>   

Unrelated to the concrete problem, consider placing templates and includes in /WEB-INF folder to prevent them from being accessed directly. See also Which XHTML files do I need to put in /WEB-INF and which not?

Burp answered 27/12, 2012 at 13:56 Comment(2)
How would one go about if updatedAddress.xhtml, selectPreferences.xhtml etc had more ui:define:s, in addition to commonBodyContent? Say, for example, a secTitle field. Is there a way to define it in updatedAddress-content.xhtml etc and use it in both updatedAddress.xhtml and summary.xhtml?Johanna
I think this is the same thing as is being asked here.Johanna

© 2022 - 2024 — McMap. All rights reserved.