我一直在与JSF一起玩,并且有一个包含页眉/页脚/导航/内容的项目 面板.但是,该项目从第1页转到第2页,依此类推,每个页面都有不同的布局.如何创建可重复使用的模板,使页面之间的外观保持相同,即页眉/页脚/导航保持不变,但内容已更新?
I have been playing with JSF and have a project working that has a header/footer/navigation/content panels. The project, however, goes from page 1 to page 2, etc., with each page having a different layout. How can I create a reusable template that keeps the same look and feel from page to page, i.e., header/footer/navigation stay the same, but content is updated?
推荐答案这听起来像是主模板的经典案例.在这样的模板中,您放置了所有页面共有的所有内容,然后您的实际页面引用了该模板并填入空白".在某种程度上,它与经典的include相反.
This sounds like a classic case of a master template. In such a template you put everything that's common to all pages and then your actual pages reference this template and "fill in the blanks". In a way it's the reverse of the also classic include.
例如
/WEB-INF/templates/masterTemplate.xhtml:
<!DOCTYPE html> <html lang="en" xmlns="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/jsf/facelets" > <h:head> <title> <ui:insert name="title">Some title</ui:insert> </title> </h:head> <ui:include src="header.xhtml"/> <h:body> <ui:insert name="content" /> </h:body> <ui:include src="footer.xhtml"/> </html>页面按如下方式使用它,例如
A page uses this as follows, e.g.
/hello.xhtml
<ui:composition template="/WEB-INF/templates/masterTemplate.xhtml" xmlns="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/jsf/facelets" > <ui:define name="title">hello</ui:define> <ui:define name="content"> Hi, this is the page </ui:define> </ui:composition>更多推荐
如何使用页眉/页脚/导航创建可重复使用的模板?
发布评论