以下代码可以在我的资源中下载
JavaServer Faces核心编程(第3版)源码
@ManagedBean
@SessionScoped
public class TableData {
private static final Name[] names = new Name[] {
new Name("William", "Dupont"),
new Name("Anna", "Keeney"),
new Name("Mariko", "Randor"),
new Name("John", "Wilson")
};
public Name[] getNames() { return names;}
}
public class Name {
private String first;
private String last;
public Name(String first, String last) {
this.first = first;
this.last = last;
}
public void setFirst(String newValue) { first = newValue; }
public String getFirst() { return first; }
public void setLast(String newValue) { last = newValue; }
public String getLast() { return last; }
}
<h:body>
#{msgs.pageTitle}
<h:form>
<h:dataTable value="#{tableData.names}" var="name">
<h:column>
#{name.last},
</h:column>
<h:column>
#{name.first}
</h:column>
</h:dataTable>
</h:form>
</h:body>
value对象表示h:dataTable迭代的数据,数据必须是下列类型之一:
- java对象
- 数组
- java.util.List实例
- java.sql.ResultSet实例
- javax.servlet.jsp.jstl.sql.Result实例
- javax.faces.model.DataModel实例
h:dataTable特性
- bgcolor 表的背景色
- border 边框宽度
- cellspacing 表格单元格之间的间距
- cellpadding表格单元格周围的边距
- columnClasses用于列,逗号分隔的css类列表
- dir未继承方向的文本的文本方向,有效值,左到右LTR,右到左RTL
- first表示显示的第一行的索引
- footerClass表尾的CSS类
- frame表周围框架边的说明,有效值:none、above、below、hsides、vsides、lhs、rhs、box、border
- headClass表头的CSS类
- rowClasses行的CSS类列表,由逗号分隔
- rows表中显示的行数,以first特性指定的行开始,如果设置为0,将显示所有行
- rules单元格间绘制的线的说明,有效值:groups、rows、columns、all
- var由数据表创建的变量的名称,表示Value中的当前项
- binding、id、rendered、styleClass、value基本特性
- lang、style、title、width html4
- onclick、ondbclick、onkeydown、onkeypress、onkeyup、onmousedown、onmousemove、onmouseout、onmouseover、onmouseup dhtml事件
<h:form>
<h:dataTable value="#{tableData.names}" var="name"
captionStyle="font-size: 0.95em; font-style:italic"
style="width: 250px;">
<f:facet