我仍然不确定是否正确使用 JSF 模板和复合组件。我需要创建一个企业 Web 应用程序,它会有很多页面。每个页面都有相同的页眉、菜单、页脚,当然还有不同的内容(= JSF 模板)。每个页面上的内容都由可重复使用的“盒子”(= JSF 复合组件)组成。这些框由一些文件、按钮等组成。我的解决方案是否正确?或者我应该使用其他技术,如自定义组件、装饰......?
布局.xhtml
<h:body>
<ui:insert name="main_menu">
<ui:include src="/xhtml/template/main_menu.xhtml"/>
</ui:insert>
<ui:insert name="header">
<ui:include src="/xhtml/template/header.xhtml"/>
</ui:insert>
<ui:insert name="content"/>
<ui:insert name="footer">
<ui:include src="/xhtml/template/footer.xhtml"/>
</ui:insert>
</h:body>
customer_overview.xhtml:
<html xmlns:cc="http://java.sun.com/jsf/composite/composite_component">
<h:body>
<!-- Facelet template -->
<ui:composition template="/xhtml/template/layout.xhtml">
<ui:define name="content">
<!-- Composite Components -->
<cc:component_case_history
caseList="#{customerOverviewController.cases}"
/>
<cc:component_customer
....
/>
...
</ui:define>
</ui:composition>
</h:body>
component_case_history.xhtml
<html xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="cases" type="java.util.List"/>
</composite:interface>
<composite:implementation>
<!-- using of "cases" -->
...
</composite:implementation>
CustomerOverviewController.java
@ManagedBean
@ViewScoped
public class CustomerOverviewController {
public List<Case> getCases() {
...
}
}
编辑 2012-04-27
基于: 何时使用 <ui:include>、标记文件、复合组件和/或自定义组件?
我认为我应该使用 Facelet 模板 + Facelet 标记文件,而不是 Facelet 模板 + 复合组件。