用 JavaServer Faces 2 实现可扩展 UI (9)
 
- UID
- 1066743
|

用 JavaServer Faces 2 实现可扩展 UI (9)
place 组件:嵌套复合组件JSF 2 让您能够在无需任何 Java 代码或配置的情况下实现完全可配置的组件。除此之外,您还可以嵌套复合组件,这样一来,您就可以将复杂的组件拆分成更小的、更易于管理的块。比如,图 8 所示的 place 组件,它能显示针对给定地址的地图和天气信息。
图 8. places 应用程序的 place 组件 清单 18 给出了 places 应用程序是如何使用 place 组件的:
清单 18. 使用 place 组件1
2
3
4
5
6
7
8
9
10
11
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:places="http://java.sun.com/jsf/composite/components/places">
<h:form id="form">
<ui:repeat value="#{places.placesList}" var="place">
<places:place location="#{place}"/>
</ui:repeat>
</h:form>
</ui:composition>
|
place 组件的代码如清单 19 所示:
清单 19. place 组件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:places="http://java.sun.com/jsf/composite/components/places">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="location" required="true"/>
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<div class="placeHeading">
<places:map title="Map"/>
<places:weather title="Weather"/>
</div>
</composite:implementation>
</html>
|
在 中,place 组件使用了两个嵌套组件:<places:map> 和 <places:weather>。 |
|
|
|
|
|