小编GoP*_*ege的帖子

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

当支持值为空时,有没有办法阻止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 …
Run Code Online (Sandbox Code Playgroud)

html datatable jsf

9
推荐指数
1
解决办法
3945
查看次数

标签 统计

datatable ×1

html ×1

jsf ×1