JSF标签之f:facet 的使用方法


f:facet标签用来为包含f:facet标签的父组件与被f:facet标签所包含的子组件之间申明一种特殊的关系。常与h:panelGrid,h:dataTable等标签连用,申明组件为标题或页脚。
在自定义组件里,我们常可利用 f:facet 为组件添加特别的属性或处理,例如MyFaces提供的翻页组件就利用f:facet制作翻页工具条。
f:facet用法例:f:facet常用用法
<jsf组件>
     <f:facet name="facet名">...jsf组件</f:facet>
</jsf组件>
在自定义组件里使用f:facet时,可以使用UIComponent.getFacets().get("facet名")方法取得指定的facet组件:
(UIComponent) getFacets().get("facet名");
h:dataTable使用f:facet例:
<h:dataTable value="#{myBean.bookList}" var= "book" border="1px">
     <h:column>
         <f:facet name="header">
             <h:outputText value="Title"/>
         </f:facet>
         <h:outputText value="#{book.title}"/>
     </h:column>
     <h:column>
         <f:facet name="header">
             <h:outputText value="Price"/>
         </f:facet>
         <h:outputText value="#{book.price}"/>
     </h:column>
</h:dataTable>
对应HTML代码:
<table border="1px">
     <thead>
         <tr>
             <th>Title</th>
             <th>Name</th>
         </tr>
     </thead>

     <tbody>
         <tr>
             <td>Hello</td>
             <td>World</td>
         </tr>
     </tbody>
</table>

浏览器显示:
Title Name Hello World
原文地址:https://www.cnblogs.com/iamconan/p/7383642.html