primefaces data exporter XLS exporting only headers not rows

五迷三道 提交于 2020-02-16 04:21:26

问题


My problems is that when I click in the button to export data table, It exports only columns headers, my excel file is generated with none rows.

<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>

I'm using primefaces 5.3 and tried to use apache poi 3.8 and 3.10-FINAL but both did not work right.

In the log i've got no errors.

Edit: I already know what is happening. The problem is that when my table is load, it's empty, but looks like the button to export It to excel, keeps some kind of cache with the table empty, and even after I load data into the table, the button keeps exporting the excel empty. Now, I don't know how to solve this problem.


回答1:


Well, if someone else get into this problem, here is the answer that corrects mine: My managed bean was request scoped. But when I clicked the button to export excel, It makes a new request to the maneged bean. And in this request my list was null. I checked this by putting a breakpoint in the method getList. So I simply change the scope of my managed bean from request scope to view scope and It works fine.




回答2:


It seems that the exporter use the property for filtered data, so at the first time, you get only headers because the filtered data is empty. I suggest try adding data to the filtered data in the load of the page.




回答3:


add f:facet header after your p:column

<p:column>
  <f:facet name="header">
    <h:outputText value="CNPJ Emissor"/>
  </f:facet>

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


来源:https://stackoverflow.com/questions/36341683/primefaces-data-exporter-xls-exporting-only-headers-not-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!