primefaces数据导出器XLS仅导出标头而不导出行 [英] primefaces data exporter XLS exporting only headers not rows

查看:76
本文介绍了primefaces数据导出器XLS仅导出标头而不导出行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我单击按钮以导出数据表时,它仅导出列标题,而我的excel文件却没有行生成.

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>

我使用的是primefaces 5.3,并尝试使用apache poi 3.8和3.10-FINAL,但两者均无法正常工作.

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.

我已经知道发生了什么事. 问题是,当我的表被加载时,它是空的,但是看起来像将其导出到excel的按钮,在表为空的情况下保持某种缓存,即使我将数据加载到表中之后,该按钮仍会继续导出excel空的. 现在,我不知道如何解决这个问题.

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.

推荐答案

好吧,如果有人遇到这个问题,这是纠正我的问题的答案: 我的托管bean受请求范围限制.但是,当我单击按钮以导出excel时,它向被装豆的豆发出了新的请求.在此请求中,我的列表为空.我通过在getList方法中放置一个断点来进行检查. 因此,我只是将托管bean的范围从请求范围更改为查看范围,就可以了.

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.

这篇关于primefaces数据导出器XLS仅导出标头而不导出行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆