Primefaces数据表 - 排序和过滤不起作用

时间:2014-05-30 08:16:16

标签: jsf jsf-2 primefaces datatable

我有一个数据表,其中包含基于所选时段和信息的动态页眉和列。问题是我在尝试排序或过滤数据时不断获取和异常。

我正在使用Primefaces 5.0,我的数据表看起来如下:

<p:scrollPanel id="reportsScroll"  style= "#{reportsMB.gridSize}" >


<p:dataTable  id="reportsTable" var="rowData" value="#{reportsMB.gridData}" widgetVar="reportsTable"
    filteredValue="#{reportsMB.filteredValues}" paginator="true" rows="100"
    currentPageReportTemplate="Displaying {startRecord} - {endRecord} of 
    {totalRecords} teams, Page: {currentPage}/{totalPages}"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks}
    {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15,25,50,100">


     <f:facet name="header">
        <p:outputPanel style="float:left">
            <h:outputText value="Search all fields:" />
            <p:inputText id="globalFilter" onkeyup="PF('reportsTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
        </p:outputPanel>
    </f:facet>

     <p:columnGroup type="header">

         <p:row>

             <c:forEach items="#{reportsMB.sumaryInfo}" var="sumary">
            <p:column rowspan="#{sumary.rows}" sortBy="#{rowData[sumary.key]}" rendered="#{sumary.name == 'User display name'}"
            filterStyle="display:none" styleClass="#{reportsMB.detailsSelected ? 'userHeaderSize' : ''}" filterBy="#{rowData[sumary.key]}"
            filterMatchMode="contains" headerText="#{sumary.name}" />

            <p:column rowspan="#{sumary.rows}" sortBy="#{rowData[sumary.key]}" rendered="#{sumary.name != 'User display name'}"
            filterStyle="display:none" styleClass="#{reportsMB.detailsSelected ? 'headerSize' : ''}" filterBy="#{rowData[sumary.key]}"
            filterMatchMode="contains" headerText="#{sumary.name}" />
            </c:forEach>

             <c:forEach items="#{reportsMB.months}" var="month">
            <p:column rendered="#{reportsMB.detailsSelected}" colspan="#{month.columns}" headerText="#{month.name}" />
            </c:forEach>

        </p:row>

          <p:row rendered="#{reportsMB.detailsSelected}">                
             <c:forEach items="#{reportsMB.weeks}" var="week">
            <p:column colspan="#{week.columns}"  headerText="#{week.name}" />
          </c:forEach>


        </p:row>


         <p:row rendered="#{reportsMB.detailsSelected}">

             <c:forEach items="#{reportsMB.daysNames}" var="dayName">
            <p:column headerText="#{dayName}"  />
            </c:forEach>

        </p:row>



        <p:row rendered="#{reportsMB.detailsSelected}">

             <c:forEach items="#{reportsMB.days}" var="day">
            <p:column headerText="#{day.name}" width="20"  sortBy="#{rowData[day.key]}" />
            </c:forEach>

        </p:row>



    </p:columnGroup>


    <p:columns value="#{reportsMB.sumaryInfo}"  var="sumary">

    <h:outputText value="#{rowData[sumary.key]}"> </h:outputText>

    </p:columns>


    <p:columns  rendered="#{reportsMB.detailsSelected}" value="#{reportsMB.days}"  var="day" id="idul">

    <h:outputText style="color:green;" rendered="#{rowData[day.key] == 'OH'}"  value="#{rowData[day.key]}"> </h:outputText>     

    <h:outputText style="color:#1cd5ed;" rendered="#{rowData[day.key] == 'REG' or rowData[day.key] == 'RES'}"  value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:red;" rendered="#{rowData[day.key] == 'SICK'}" value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:black;" rendered="#{rowData[day.key] == 'UNP'}"  value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:#ff69b4;" rendered="#{rowData[day.key] == 'SPEC'}"  value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:orange;" rendered="#{rowData[day.key] == 'OVRT'}"  value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:gray;" rendered="#{rowData[day.key] == 'WE'}"  value="#{rowData[day.key]}"> </h:outputText>

    <h:outputText style="color:black;" rendered="#{rowData[day.key] == 'NH' or rowData[day.key] == 'GONE'}"  value="#{rowData[day.key]}"> </h:outputText>

    </p:columns>

例外是:

May 30, 2014 11:13:27 AM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: javax.faces.FacesException: Cannot find column with key: datatable:reportsTable:j_idt99
javax.faces.FacesException: Cannot find column with key: datatable:reportsTable:j_idt99
    at org.primefaces.component.datatable.DataTable.findColumn(DataTable.java:773)
    at org.primefaces.component.datatable.feature.SortFeature.decode(SortFeature.java:87)
    at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:61)
May 30, 2014 11:13:27 AM com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit
SEVERE: javax.el.ELException: Error Parsing: #{rowData.null}

谁能告诉我如何让它发挥作用?谢谢!

2 个答案:

答案 0 :(得分:0)

此行onkeyup="PF('reportsTable').filter()"不正确,因为reportsTable被定义为ID。它应该被定义为一个widgetVar。因此,添加widgetVar="reportsTable"可能会解决您的问题。

答案 1 :(得分:0)

上次类似的事情发生在我身上时,我忘记用data标签封装dataTable。这是一个简单的想法,但我花了一些时间试图找到问题。