我们如何将多个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>
<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>
<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>
<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>
<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>
文档。
我们如何解决这个问题?
答案 0 :(得分:7)
将正文内容移动到模板客户端中<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
文件夹中放置模板和包含,以防止直接访问它们。另请参阅Which XHTML files do I need to put in /WEB-INF and which not?