【问题标题】:Why datatable adds more <td> to my table为什么 datatable 会在我的表中添加更多 <td>
【发布时间】:2013-04-18 15:08:08
【问题描述】:

这是我的 jsf:

 <h:dataTable class="pretty" value="#{ftController.ftDataModel}" var="item">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Amount"/>
                        </f:facet>
                    </h:column>
                    <h:column >
                        <f:facet class="right" name="header">
                            <h:outputText value="Date"/>
                        </f:facet>
                    </h:column>
                    <h:column>      
                        <h:outputLink   value="index.jsf"><h:outputText value="#{item.ftType}"/></h:outputLink><br />
                          <h:outputText class="red" id="amount"   value="#{item.amount}"></h:outputText> <h:outputText value="&#160;" /><h:outputText  style="font-size:12px" class="gray" value="TL" />
                    </h:column>
                    <h:column class="right" >
                        <h:outputText id="date"    value="#{item.date}"></h:outputText> 
                    </h:column>
                </h:dataTable>

但是,html 输出是这样的:

<table class="pretty">
<thead>
<tr>
<th scope="col">Amount</th>
<th scope="col">Date</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td><a href="index.jsf" class="ui-link">Person</a><br><span id="j_idt8:j_idt21:0:amount" class="red">34500.6</span>&nbsp;<span class="gray" style="font-size:12px">TL</span></td>
<td><span id="j_idt8:j_idt21:0:date">10/14/2012</span></td>
</tr>
<tr>
<td></td>
<td></td>
<td><a href="index.jsf" class="ui-link">Person</a><br><span id="j_idt8:j_idt21:1:amount" class="red">3444.78</span>&nbsp;<span class="gray" style="font-size:12px">TL</span></td>
<td><span id="j_idt8:j_idt21:1:date">10/15/2012</span></td>
</tr>
</tbody>
</table>

它在金额和日期下为 ex 添加了额外的&lt;th&gt;。它还添加了&lt;td&gt;s 为什么?这里有什么问题?我该如何解决?为什么要添加?

【问题讨论】:

  • 您因此面临什么问题?
  • 它只是数据表的 HTNL 源。 Column facet== HTML thcolumn== HTML td
  • 这是预期的行为。您定义了 4 个&lt;p:column&gt;。所以它增加了 4 个&lt;td&gt; 和 4 个&lt;th&gt;
  • 请务必查看如何在 JSF 数据表中使用 header facet。

标签: java jsf


【解决方案1】:

只需将&lt;f:facet&gt; 嵌套在&lt;h:column&gt;一起 与行数据。您在代码中告诉 JSF 的是创建 4 列,其中前两列将包含空行数据和定义的标题文本,而后两列将反转所有内容。像这样修复它:

            <h:dataTable class="pretty" value="#{ftController.ftDataModel}" var="item">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Amount"/>
                    </f:facet>
                    <h:outputLink   value="index.jsf"><h:outputText value="#{item.ftType}"/></h:outputLink><br />
                      <h:outputText class="red" id="amount"   value="#{item.amount}"></h:outputText> <h:outputText value="&#160;" /><h:outputText  style="font-size:12px" class="gray" value="TL" />
                </h:column>
                <h:column >
                    <f:facet class="right" name="header">
                        <h:outputText value="Date"/>
                    </f:facet>
                    <h:outputText id="date"    value="#{item.date}"></h:outputText> 
                </h:column>
            </h:dataTable>

【讨论】:

    【解决方案2】:

    这是因为您的数据表中有 4 个&lt;h:column&gt;。并且 3rd 和 4th 没有 name 属性,所以它是空白的。

    【讨论】:

      猜你喜欢
      • 2011-12-25
      • 2021-05-01
      • 1970-01-01
      • 2012-11-28
      • 2016-07-16
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      相关资源
      最近更新 更多