how to include multiple xhtml pages, which are extending same template into a summary xhtml page,
17,610
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?
Author by
uday
Updated on June 20, 2022Comments
-
uday almost 2 years
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 ?