【发布时间】:2014-05-25 08:46:50
【问题描述】:
我已经分三步完成了模板:
首先,我创建了一个 xhtml 文件,其中包含所有页面共有的内容:
AllComponentsTemplate.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>State Transport Department- Work Schedule</title>
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" type="text/css" href="../../CSS/CompleteTemplateCSS.css"/>
<link rel="stylesheet" type="text/css" href="../../CSS/templateCSS.css"/>
</head>
<body>
<div class="container">
<div class="header"></div>
<div class="menu">
<h:outputLabel class="welcomeNote" value="#{welcomeBean.fullname}" />
<ul class="ulForMyAccount"><li> <h:outputLabel value="My Account" id="mainAnchor"/>
<ul ><li> <a href="/webpages/ChangePasswordxhtml.xhtml" id="subAnchor" >Change my Password</a> </li> </ul></li></ul> </div>
<div class="contentBody">
<div class="menuTable">
<table class="templateBody" >
<tr>
<td class="navigationLink" > <ul><li>
<h:link value="Home" outcome="/webpages/NewWelcome.xhtml" rendered="#{welcomeBean.home}" class="mainLinks"/>
</li></ul> </td>
</tr> </table> </div> </div>
<div class="footer"></div>
</div> </body> </html>
然后我创建了一个 MainTemplate.xhtml 页面,我将在其他页面中将其用作模板:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>
<h:head>
<title>State Transport Department-Work Schedule</title>
</h:head>
<h:body>
<ui:include src="AllComponentsTemplate.xhtml"/>
<ui:insert name="informationBody"></ui:insert>
</h:body> </f:view> </html>
然后我将此模板添加到我的第一页 Trial.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/webpages/templates/CompleteTemplate.xhtml">
<ui:define name="informationBody">
<h:form>
<h:commandButton id="allocateButton" value="Test Submit" action="#{empDutySchedBean.testMethod}"/>
</h:form>
</ui:define>
</ui:composition>
注意:trial.xhtml 没有有html、head、body标签。
问题:直到 MainTemplate.xhtml 页面,包括链接等的所有组件都完全可见。 但是在将模板包含到 Trial.xhtml 页面后,我的帐户、欢迎标签、主页导航链接没有不出现。
除此之外,我申请的网页背景颜色的所有css都出现了。
我不知道为什么。帮助将不胜感激。我是编码初学者。
谢谢! :)
【问题讨论】:
-
我已经更新了我的答案,提出了重组的建议。