f:facet

《Java Server Faces 2.0,The Complete Reference》對f:facet是這樣解釋的:

 

The f:facet tag signifies a nested component that has a special relationship to its enclosing

tag. For example, stating that the “header” of a table is to be provided by a JSF component.

This element adds the component represented by the JSF action in its body as a facet with

the specified name to the component represented by the closest JSF component parent

action element. This tag only allows one component to be nested within itself. To use

multiple components as a facet, create them as children of a simple container component.

For example, nest the corresponding HTML library component actions within the body of

a panelGroup component.

意思是:f:facet表示一個"被嵌套組件",這個組件和包含它的標籤有特定關係的。...(<f:facet>被嵌套組件</f:facet>,一次只能包含一個"被嵌套組件")

 

 

JSFToolBox網站上是這樣解釋的:

 

The Facet tag registers a named facet on the component associated with the enclosing tag. A facet represents a named section within a container component. For example, you can create a header and a footer facet for a dataTable component.

意思和上面差不多。

 

 

能找到的資料上基本都是舉這樣一個例子來試圖說明f:facet的用法:

 

疑問來了,既然name="****"代表的是facet與包含它的組件的關係,那麼這個關係是不是可以自己隨便寫呢?"被嵌套組件"是不是可以隨便寫呢?

改寫上面的代碼:

 

運行發現header變成了不再是文字,而是一個輸入框,

<f:facet name="relation"> <h:outputText value="Daily Report" /> </f:facet>沒有任何輸出。

 

結論:

The name attribute sets the name of the facet to be created. Some components have facets with predefined names, such as the "header" and "footer" facets of the component associated with the h:dataTable tag.

 

只有組件預先就定義好的name的facet才能被接受,比如h:dataTable就預先定義了名爲"header"和"footer"的facet。<f:facet>標籤對之間的內容可以是任意組件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章