JSF h:dataTable在没有记录时创建单个空单元格

GoP*_*ege 9 html datatable jsf

当支持值为空时,有没有办法阻止h:datatable创建一个空行?更具体地说:我有一组数据要显示在带有列标题的h:dataTable中的3列中.无论列表中是否有元素,都需要显示thead.这很好,但是当列表中没有元素时,会在tbody中创建一个空的行/单元格.有办法防止这种情况吗?

谢谢!

来自backing bean的示例方法.为了测试我尝试返回null或空列表.两者的结果相同.

    public List<LocationsDecorator> getLocations() {
    return null;
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

产生的HTML(<tr><td></td></tr>tbody中的" "是问题):

<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>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 5

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

table.empty tbody td {
    border: 0;
}
Run Code Online (Sandbox Code Playgroud)

并有条件地添加它.

<h:dataTable ... styleClass="locations #{empty component.value ? 'empty' : ''}">
Run Code Online (Sandbox Code Playgroud)