Facelets 標籤參考 2html
lxm翻譯自《Facelets Essentials: Guide to JavaServer™ Faces View Definition Framework 》java
不當之處歡迎指正。ide
這標籤是開發程序時頗有用的工具。在 launched 的時候經過按組合健 Ctrl + Shift + < 熱鍵 > ( 默認是 D) ,將顯示一個彈出窗口,在裏面顯示組件樹和局部變量,表格 1-6 列出它的屬性。工具
表格 1-6: <ui:component> 標籤屬性ui
屬性名稱this |
必需spa |
描述翻譯 |
hotkeydebug |
否調試 |
熱鍵, 默認是 D 。 |
rendered |
否 |
boolean 值,指定是否顯示 . |
一般,能夠在頁面的末尾找到 debug 標籤 , 但它能夠定義在任何位置,能夠定義 以下 :
<ui:debug hotkey="g"
rendered="#{initParam[‘apress.DEBUG_MODE’]}"/>
這樣 , 按 Ctrl + Shift + G 就能夠彈出調試窗口,在 initParam[‘apress.DEBUG_MODE’] 中指定是否顯示。
<ui:param/> 用來在 Facelets 之間用名字變量傳遞對象。 下列表格列出它的屬性。
表格 : <ui:param> 標籤屬性
屬性名稱 |
必需 |
描述 |
name |
是 |
傳遞給被包含文件或是模板文件的變量的名稱 . |
value |
是 |
用簡單或 EL 表達式的值給名字變量賦值。 |
舉例:
Listing 1-17. param-details.xhtml
<!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:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition>
<div>
<h3>#{birdName}</h3>
Order: #{birdOrder}
<br/>
Family: #{birdFamily}
</div>
</ui:composition>
</body>
</html>
在下面文件中引用前面定義的模板文件
Listing 1-18. param-example.xhtml
<!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:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:include src="param-details.xhtml">
<ui:param name="birdName" value="Parrot"/>
<ui:param name="birdOrder" value="Psittaciformes"/>
<ui:param name="birdFamily" value="Psittacidae"/>
</ui:include>
<ui:decorate template="param-details.xhtml">
<ui:param name="birdName" value="Eagle"/>
<ui:param name="birdOrder" value="Falconiformes"/>
<ui:param name="birdFamily" value="Accipitridae"/>
</ui:decorate>
</body>
</html>
產生以下輸出:
<div>
<h3>Parrot</h3>
Order: Psittaciformes
<br />
Family: Psittacidae
</div>
<div>
<h3>Eagle</h3>
Order: Falconiformes
<br />
Family: Accipitridae
</div>
<ui:remove> 用來在在編譯時移除代碼塊,它沒有屬性,能夠在 jsfc 的屬性中指定。
例如:
<ui:remove>
This will be removed.
</ui:remove>
This will survive
<div jsfc="ui:remove">
This will be removed too
<h:outputText value="#{backingBean.andThisToo}"/>
</div>
And this will survive too!
產生以下輸出:
This will survive
This will survive too!
<ui:repeat/> 用來跌代一個對象列表。推薦用 JSTL 核心標籤庫中的 c:forEach 代替。不做介紹。