【问题标题】:var attribute of p:datatable is null in header facetp:datatable 的 var 属性在标头方面为空
【发布时间】:2013-04-02 07:25:57
【问题描述】:

我有这样的数据表:

  <p:dataTable value="#{noteMB.noteList}" var="noteItem" id="noteListTable" 
        rowKey="#{noteItem.hashCode()}" selectionMode="single"  selection="#noteMB.selectedNote}" paginator="true" rows="10" paginatorPosition="top"
        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15">

    <p:column width="300">
       <f:facet name="header">
            <h:outputText value="#{noteItem.name == 'blabla' ? 'true' : 'false' }"  />
       </f:facet> 
            <h:outputText value="#{noteItem.code}"  />
    </p:column>
  </p:dataTable>

我的问题:为什么 noteItem 在 facet name="header" 区域中为空? 当我运行此代码时,标题(noteItem.name)为假,列值(noteItem.code)有一个值。

【问题讨论】:

  • 其实noteItem为空
  • 嗯,这可能导致它在生成表本身之前被处理,它用于标题数据,所以你不能指望它能够访问列表元素......

标签: primefaces jsf-2


【解决方案1】:

noteItem 是您的 var 条目。

var="noteItem"

这个 var 属性假定为dataTable 的每一行保存变量项。 var 将遍历 noteList 中的每个项目。

正如丹尼尔所说,在h:facet 标签期间,甚至没有开始创建行。它是每一列的主标题,实际上没有数据表行。 因此,您在那里得到空值。

简而言之,你不能访问 facets 中 var 属性给出的对象。 因为构面是行独立的

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多