【问题标题】:How do I just display a table header if a jsf datatable is empty? [duplicate]如果 jsf 数据表为空,我如何只显示表头? [复制]
【发布时间】:2015-11-14 13:32:38
【问题描述】:

我遇到了如下图所示的问题:

please click me to see pic

代码如下,这里#{userData.basicInfoList}为空时多了一个标题行:

<h:dataTable id="userData" value="#{userData.basicInfoList}" var="info"
border="1" width="100%" style="margin-top: 10px"
headerClass="headerStyle"
columnClasses="user-id, user-name, user-age, user-sex, user-address, user-phone-no">
<h:column>
    <f:facet name="header">
        <h:outputText value="id" />
    </f:facet>
    <h:outputText value="#{info.id}" />
</h:column>

<h:column>
    <f:facet name="header">
        <h:outputText value="name" />
    </f:facet>
    <h:outputText value="#{info.name}" />
</h:column>

<h:column>
    <f:facet name="header">
        <h:outputText value="age" />
    </f:facet>
    <h:outputText value="#{info.age}" />
</h:column>

<h:column>
    <f:facet name="header">
        <h:outputText value="sex" />
    </f:facet>
    <h:outputText value="#{info.sex}" />
</h:column>

<h:column>
    <f:facet name="header">
        <h:outputText value="address" />
    </f:facet>
    <h:outputText value="#{info.address}" />
</h:column>
<h:column>
    <f:facet name="header">
        <h:outputText value="phone no" />
    </f:facet>
    <h:outputText value="#{info.phoneNo}" />
</h:column>

渲染的html如下:

<table id="heForm:userData" border="1" style="margin-top: 10px"
width="100%">
<thead>
    <tr>
        <th class="headerStyle" scope="col">id</th>
        <th class="headerStyle" scope="col">name</th>
        <th class="headerStyle" scope="col">age</th>
        <th class="headerStyle" scope="col">sex</th>
        <th class="headerStyle" scope="col">address</th>
        <th class="headerStyle" scope="col">phone no</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td></td>
    </tr>
</tbody>

【问题讨论】:

  • 右键单击空白单元格,然后单击子菜单中的“检查元素”选项,然后检查空白单元格中正在呈现的元素。
  • 嗨,渲染 html 已添加。如何解决?

标签: jsf datatable


【解决方案1】:

最佳解决方案如下:

<h:dataTable ... styleClass="#{empty userData.basicInfoList ? 'empty' : ''}">

独立风格:

.empty tbody td{
    border-color: rgba(0, 0, 0, 0);
}

【讨论】:

  • 如果您改进了另一个问题,请将其标记为重复(或删除)
【解决方案2】:

这是 h:dataTable 的默认行为

这是一个副本

See @Balusc answer

【讨论】:

  • 感谢您的回答!它帮助我解决问题。并且我稍微修正了 BalusC 的代码,它现在可以工作了!
  • 如果您能将我的答案标记为有效并投赞成票,我将不胜感激
  • 好的,请帮我为我改进的解决方案投票,谢谢!
  • 对不起,我的声望不够投票。
  • 如果是重复的,标记为这样(见标志选项)不需要添加它作为答案。
猜你喜欢
  • 2010-12-31
  • 1970-01-01
  • 1970-01-01
  • 2013-04-27
  • 2020-05-13
  • 2016-10-17
  • 1970-01-01
  • 2011-08-27
相关资源
最近更新 更多