绿野仙棕

常用链接

统计

hibernate技术

最新评论

JSF DataTable 学习(2)

h:dataTable标签用来生成表格,感觉就和struts的logic:iterator差不多,下面是一般的用法:

其中这个items可以是一个集合(其类型可以是array、java.util.List、java.sql.ResultSet、javax.servlet.jsp.jstl.sql.Result、javax.faces.model.DataModel,循环遍历所有的item),或者是其他任何非集合的元素(循环一次)。
注意1)h:dataTable里面只能包含h:column。2)在h:dataTable这种能render子元素的标签中,要显示原始文本的话,要用<f:verbatim></f:verbatim>将文本包含起来(或者用h:outputText)。3) <f:facet name="header">和<f:facet name="footer">可以制定表头和表尾。

h:dataTable有以下这些属性:

bgcolor
 Background color for the table
 
border
 Width of the table's border
 
cellpadding
 Padding around table cells
 
cellspacing
 Spacing between table cells
 
columnClasses
 Comma-separated list of CSS classes for columns
 
first
 Index of the first row shown in the table
 
footerClass
 CSS class for the table footer
 
frame
 Specification for sides of the frame surrounding the table should be drawn; valid values: none, above, below, hsides, vsides, lhs, rhs, box, border
 
headerClass
 CSS class for the table header
 
rowClasses
 Comma-separated list of CSS classes for columns
 
rules
 Specification for lines drawn between cells; valid values: groups, rows, columns, all
 
summary
 Summary of the table's purpose and structure used for non-visual feedback such as speech
 
var
 The name of the variable created by the data table that represents the current item in the value
 
binding, id, rendered, styleClass, value
 Basic attributes
 
dir, lang, style, title, width
 HTML 4.0
 
onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup
 DHTML events


有一个很有意思的例子,它可以生成一个动态可编辑的表格:

事实上,h:dataTable不是直接操作集合对象的,而是通过Table Models来实现的。所以我们可以通过getWrappedData()和setWrappedData()来实现对modle中对象的操作,比如下面的一个方法:

同时如果我们要对集合数据进行排序和过滤的话,我们必须通过继承一种table model来实现。

posted on 2006-09-28 12:12 土牛小屋 阅读(2979) 评论(2)  编辑  收藏 所属分类: jsf技术

评论

# re: JSF DataTable 学习(2) 2008-05-09 16:39 小曾

你好,如果我 要输出宽度为300,2列的表格。第一列宽为100,第二列的宽为200,第一列里的内容要粗体,第二列的内容字体为红色。内容用h:outputText输出,那我该怎么写呢。谢谢  回复  更多评论   

# re: JSF DataTable 学习(2) 2010-05-05 23:23 liuche

能否给出一个排序的例子?谢谢啦!
wnh5@tom.com  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: