首页 技术 正文
技术 2022年11月15日
0 收藏 493 点赞 4,026 浏览 1429 个字

来看看简单的datatable例子:

faces:

<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>

在上面的页面中有几个属性值得注意,

value:表示数据源,一般为List、ArrayList、数组等,是从bean得到的数据

var:可以看着是数据源中的一条数据的别名。

在看看bean如下:

@Named // or @ManagedBean
@SessionScoped
public class TableData implements Serializable {
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;}
}

就这样一个简单datatable例子。

在开发中一般表格都是有表头和表尾的,表头在DataTable中用<f:facet name=”header”>表示。修改下上面faces如下:

<h:dataTable value="#{tableData.names}" var="name">
<h:column>
<f:facet name="header">last</f:facet>
#{name.last},
</h:column> <h:column>
<f:facet name="header">first</f:facet>
#{name.first}
</h:column>
</h:dataTable>

当然样式是可以自己控制的。

二:

在我们快速开发中特别是在MVC中使用HTML标签很多。这里还有一种方法来代替Datatable比如下面的例子:

<table class="table-list">
<thead>
<tr>
<th></th>
<th style="width:140px">
ISBN
</th>
<th style="width:182px">
书名
</th>
<th>
出版日期
</th>
<th>
单价
</th> </tr>
</thead>
<tbody>
<ui:repeat value="#{summary.data}" var="name" varStatus="status">
<tr>
<td>#{status.index + 1}</td>
<td>
#{name.isbn}
</td>
<td title="#{name.title}">
<input type="text" readonly="readonly" value="#{name.title}" style="background-color:#FFFFFF; border:1px; width:180px;" />
</td>
<td>
#{name.pubdate}
</td>
<td>
#{name.price}
</td>
</tr>
</ui:repeat>
</tbody>
</table>

<ui:repeat>来代替DataTable。
repeat的具体用法和datatable一样。。
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292