JSF h:dataTable在没有记录时创建单个空单元格 [英] JSF h:dataTable creates single empty cell when no records

查看:301
本文介绍了JSF h:dataTable在没有记录时创建单个空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当背景值为空时,是否有任何方法可以防止h:datatable创建空行?
更具体来说:
我有一个数据集合,在h列表中的3列中显示:具有列标题的数据表。总是需要显示thead,无论列表中是否有元素。这样做很好,但是当列表中没有元素时,在tbody中创建一个单独的空行/单元格。有办法防止这种情况吗?

Is there any way to prevent an h:datatable from creating an empty row when the backing value is empty? More specifically: I have a collection of data to be displayed in 3 columns in an h:dataTable with column headers. The thead always needs to be displayed, regardless of if there are elements in the list. This works fine, but when no elements are in the list, a single, empty row/cell is created in the tbody. Is there a way to prevent this?

谢谢!

从支持bean的示例方法。为了测试我已经尝试返回null或空列表。

Sample method from backing bean. For testing i've tried returning both null or an empty list. Same result for both.

    public List<LocationsDecorator> getLocations() {
    return null;
}

JSF片段:

<h:dataTable styleClass="locations" id="locations1"
    var="nearestLoc" value="#{confirmationBean.locations}">
    <h:column>
        <!-- column header -->
        <f:facet name="header">Address</f:facet>
        <!-- row record -->
            #{nearestLoc.adddress}
        </h:column>
    <h:column>
        <!-- column header -->
        <f:facet name="header">Distance</f:facet>
        <!-- row record -->
            #{nearestLoc.distance}
        </h:column>
    <h:column>
        <!-- column header -->
        <f:facet name="header">Hours of Operation</f:facet>
        <!-- row record -->
        <h:dataTable styleClass="locations" var="data"
            value="#{nearestLoc.hoursOfOperation}">
            <h:column>     
                #{data}
                </h:column>
        </h:dataTable>

    </h:column>

</h:dataTable>

生成的HTML(< tr>< td> / t>< / tr> 在tbody中是问题):

Resulting HTML(The "<tr><td></td></tr>" in the tbody is the problem):

<table id="contact:locations1" class="locations">
<thead>
<tr>
<th scope="col">Address</th>
<th scope="col">Distance</th>
<th scope="col">Hours of Operation</th>
</tr>
</thead>
<tbody>
<tr><td></td></tr></tbody>
</table>


推荐答案

为空表指定单独的样式。例如

Specify a separate style for an empty table. E.g.

table.empty tbody td {
    border: 0;
}

有条件地添加。

<h:dataTable ... styleClass="locations #{empty component.value ? 'empty' : ''}">

这篇关于JSF h:dataTable在没有记录时创建单个空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆