primefaces数据导出器XLS仅导出标头而不是行

时间:2016-03-31 19:08:00

标签: jsf primefaces data-export

我的问题是,当我单击按钮导出数据表时,它只导出列标题,生成的excel文件没有任何行。

<h:form>


    <p:dataTable id="cteTable" var="cte" 
        emptyMessage="Nenhum Registro Localizado"
        reflow="true" value="#{extratorBean.ctes}" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
        style="margin-top: 10px" paginator="true" rows="100" scrollable="true" scrollWidth="1024px">

        <f:facet name="{Exporters}">
            <h:commandLink>
                <p:graphicImage name="images/excel.png" width="24" library="samsung" />
                <p:dataExporter type="xls" target="cteTable" fileName="cte-s" />
            </h:commandLink>
        </f:facet>

        <p:column headerText="CNPJ Emissor" width="150" style="text-align: center">
            <h:outputText value="#{cte.EMIT_CNPJ}"/>
        </p:column>

        <p:column headerText="Serie" width="60" style="text-align: center">
            <h:outputText value="#{cte.IDE_SERIE}"/>
        </p:column>

        <p:column headerText="N° CT-e" width="90" style="text-align: center">
            <h:outputText value="#{cte.IDE_NCT}"/>
        </p:column>

        <p:column headerText="Dt. Emissão" width="150" style="text-align: center">
            <h:outputText value="#{cte.IDE_DHEMI}">
                <f:convertDateTime pattern="dd/MM/yyyy" />
            </h:outputText>
        </p:column>

        <p:column headerText="Total Frete" width="80" style="text-align: center">
            <h:outputText value="#{cte.VPREST_VTPREST}">
                <f:convertNumber type="currency" />
            </h:outputText>
        </p:column>

        <p:column headerText="ICMS" width="80" style="text-align: center">
            <h:outputText value="#{cte.ICMS_VICMS}">
                <f:convertNumber type="currency" />
            </h:outputText>
        </p:column>

        <p:column headerText="% ICMS" width="80" style="text-align: center">
            <h:outputText value="#{cte.ICMS_PICMS}">
                <f:convertNumber minFractionDigits="2" />
            </h:outputText>             
        </p:column>

        <p:column headerText="Nat. Op." width="350" style="text-align: center">
            <h:outputText value="#{cte.IDE_NATOP}"/>
        </p:column>

        <p:column headerText="CNPJ Tomador" width="150" style="text-align: center">
            <h:outputText value="#{cte.TOMADOR}"/>
        </p:column>

        <p:column headerText="Chave Acesso" width="350" style="text-align: center">
            <h:outputText value="#{cte.TRANSACTIONID}"/>
        </p:column>

        <p:column headerText="Dt. Criação" width="120" style="text-align: center">
            <h:outputText value="#{cte.IDE_TIMESTAMP}">
                <f:convertDateTime pattern="dd/MM/yyyy" />
            </h:outputText>
        </p:column>

        <p:column headerText="N° Protocolo" width="120" style="text-align: center">
            <h:outputText value="#{cte.IDE_AUTHCODESEFAZ}"/>
        </p:column>

    </p:dataTable>
</h:form>

我正在使用primefaces 5.3并尝试使用apache poi 3.8和3.10-FINAL,但两者都无法正常工作。

在日志中我没有错误。

编辑:我已经知道发生了什么。 问题是当我的表加载时,它是空的,但看起来像是将它导出到excel的按钮,保持表空的某种缓存,甚至在我将数据加载到表后,按钮继续导出excel空。 现在,我不知道如何解决这个问题。

3 个答案:

答案 0 :(得分:1)

似乎导出器将该属性用于过滤数据,因此第一次只获取标头,因为过滤后的数据为空。我建议尝试将数据添加到页面加载中的过滤数据中。

答案 1 :(得分:0)

好吧,如果其他人遇到这个问题,这里的答案就是纠正我的: 我的托管bean是请求作用域。但是当我单击按钮导出excel时,它会向maneged bean发出新请求。在此请求中,我的列表为空。我通过在方法getList中放置一个断点来检查这一点。 所以我只是将托管bean的范围从请求范围更改为查看范围,并且工作正常。

答案 2 :(得分:-1)

在p:列

之后添加f:facet标头
<p:column>
  <f:facet name="header">
    <h:outputText value="CNPJ Emissor"/>
  </f:facet>

  <h:outputText value="#{cte.EMIT_CNPJ}"/>
</p:column>