我仍然不確定如何正確使用JSF模板複合組件。我需要創建一個企業Web應用程序,這將有很多頁面。每個頁面都有相同的標題,菜單,頁腳和當然不同的內容(= JSF模板)。每個頁面上的內容將由可重複使用的「框」(= JSF複合組件)組成。箱子由一些文件夾,按鈕等組成。我的解決方案是否合適?或者我應該使用其他技術,如自定義組件,裝飾...?正確使用Facelet模板和複合組件
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>
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
: When to use <ui:include>, tag files, composite components and/or custom components?
我認爲我應該使用,而一個facelet模板+ Facelet標記文件,而不是一個facelet模板+複合材料部件。
你可以讓你的問題更具體嗎?基本思想是模板將有多個客戶端,允許重複使用。所有客戶共享相同的外觀和感覺,並相互導航。 xhtml非常簡單,在我的(有限)體驗中,JSF 2.1導航並不那麼重要。當然,您可以擁有代碼片段,頭文件和不包含的內容,以便您的HTML遵循DRY。你在問什麼?順便說一句,'@ManagedBean'與'@Named'非常不同,僅供參考。 – Thufir 2012-04-08 06:14:38
@Thufir:我問我是否應該使用我的Web應用程序JSF模板(基於您的評論,答案是YES),如果我應該使用必須是可重用JSF複合組件的「盒子」不同(裝飾,自定義組件)..不確定。我不知道你的意思是「HTML遵循DRY」,不知道你爲什麼提到'@ManagedBean'與'@Named'非常不同。 – Ziletka 2012-04-08 09:34:17
DRY ==「不要重複你自己」,參見維基百科。哦,我提到了'@Named',因爲我在戰鬥 - 與你的問題無關,對不起。 – Thufir 2012-04-08 18:27:48