【发布时间】:2016-11-16 09:53:40
【问题描述】:
我刚刚了解到我可以创建一个主模板,我可以使用ui:insert、ui:define 和ui:include src将其替换为不同的其他xhtml 页面,所以我在网上做了一些研究并尝试显示合并页面。
但是,我无法用另一个内容定义命名的 ui:insert content 块(我想在用户进入注册页面时输入 register.xhtml 页面的内容)
template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<h:outputStylesheet name="css/bootstrap.css" />
<h:outputStylesheet name="css/font-awesome.css"/>
<h:outputStylesheet name="css/mywebsite.css"/>
<h:outputScript name="js/jquery-3.1.1.js"/>
<h:outputScript name="js/bootstrap.js"/>
</h:head>
<h:body>
<div id="page">
<div id="header">
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
</div>
<div id="content">
<!--content container-->
<ui:insert name="content">
<ui:include src="content.xhtml" />
</ui:insert>
</div>
<div id="footer">
<!--footer container-->
<ui:insert name="footer">
<ui:include src="footer.xhtml" />
</ui:insert>
</div>
</div>
</h:body>
</html>
header.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h1>Default Header</h1>
</ui:composition>
content.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
>
<h1>Default Content</h1>
</ui:composition>
footer.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h1>Default Footer</h1>
</ui:composition>
register.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h1>I AM REGISTER</h1>
</ui:composition>
当用户转到 localhost:8080/mywebsite/register.xhtml 时,我希望能够将 content 块替换为 register.xhtml
我想替换 default content div。仅当用户进入 注册 页面 (localhost:8080/mywebsite/register.xhtml) 但保留 header 和 footer。
希望你能帮忙。
谢谢。
【问题讨论】:
标签: jsf