我最近开始使用带有Facelets的JSF 2.0,并且对于了解<ui:include>Facelets 1.x提供的现有和其他模板技术的新复合组件感到困惑.
这些方法有什么区别?从功能上看,它们似乎提供了相同的:<ui:param>vs <cc:attribute>,<ui:insert>+ <ui:define>vs标记文件,重用现有模板.除了复合组件的语法和清晰的接口规范之外还有什么吗?性能会有所不同?
我仍然不确定正确使用JSF模板和复合组件.我需要创建一个企业Web应用程序,它将拥有大量页面.每个页面都有相同的标题,菜单,页脚,当然还有不同的内容(= JSF模板).每个页面上的内容将由可重复使用的"框"(= JSF复合组件)组成.这些盒子包括一些文件,按钮等.我的解决方案是否合适?或者我应该使用其他技术,如自定义组件,装饰......?
layout.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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
CustomerOverviewController.java
@ManagedBean
@ViewScoped
public class CustomerOverviewController {
public List<Case> getCases() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2012-04-27 …