JSF标签之f:facet 的用法

版权声明:本文为博主原创文章,未经博主同意不得转载。

https://blog.csdn.net/zkn_CS_DN_2013/article/details/33717091


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

猜你喜欢

转载自www.cnblogs.com/mqxnongmin/p/10545665.html