[英]JSF 2 - construct a page from two files - main and current content
I'm quite new to using JSF and I'm not sure if that's the right way to go, but in Rails you usually have a main application file into which the current page is loaded. 我对使用JSF很陌生,我不确定这是否是正确的方法,但是在Rails中,您通常会有一个主应用程序文件,该文件将当前页面加载到该文件中。 That way I don't have to worry about copy-pasting the menu, etc. every time. 这样,我不必每次都担心复制粘贴菜单等问题。
How can I achieve that with JSF 2? 如何使用JSF 2实现呢? Can I navigate to the same main page every time and tell it to load a current content? 我可以每次导航到相同的主页并告诉它加载当前内容吗? Or do I tell the current page that I navigate to to load the "main frame around the content"? 还是我告诉当前页面我要导航以加载“内容周围的主框架”?
Thanks! 谢谢!
Yes of course, JSF 2.0 has page-templating feature . 是的,当然,JSF 2.0具有页面模板功能 。 You define a template that defines a generic layout to all the view pages. 您定义一个模板,该模板为所有视图页面定义通用布局。
Facelets tags to create basic page: Facelets标签创建基本页面:
ui:insert
; ui:define –定义插入标签ui:insert
; For example: 例如:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/templates/myLayout.xhtml">
<ui:define name="menu">
<ui:include src="/mypath/menu.xhtml"/>
</ui:define>
<ui:define name="content">
<ui:include src="/mypath/content.xhtml"/>
</ui:define>
</ui:composition>
or 要么
<ui:insert name="content">
<ui:include src="/mypath/mycontent.xhtml"/>
</ui:insert>
JSF doesn't support what you want to archive. JSF不支持您要归档的内容。 Instead, it support the views and basic layout(template). 相反,它支持视图和基本布局(模板)。 What you need it this: 您需要什么:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="path/to/template.xhtml>
<your custom content here/>
<ui:composition/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.