Primefaces数据导出器在Excel中导出空值

我有一个页面,我加载一些数据到一个数据表,并提供一个button导出到XLS。 我用Primefaces在其网页和XLS文件下载相同的示例代码,但是当我打开它,我发现它尽pipedatable包含值为空。 我正在使用Primefaces 4.0,这是我的XHTML页面

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:p="http://primefaces.org/ui" template="/WEB-INF/templates/default.xhtml"> <ui:define name="content"> <h:head> </h:head> <body style="background-image: url('#{request.contextPath}/resources/gfx/Whitewallpaper.jpg')"> <h:form id="form"> <p:tabView id="tabview" orientation="left" style="width : 1200px; " > <p:tab title="Visualiser "> <p:panel header=" " > <h:commandLink > <p:commandButton value="exporter" /> <p:dataExporter type="xls" target="crs" fileName="prixde" pageOnly="true" /> </h:commandLink> <p:dataTable id="crs" var="car" value="#{marchebean.selectedmarche.marchetraveau}" > <f:facet name="header"> <center> Tbaleau des travaux </center> </f:facet> <f:facet name="footer"> <h3> Total HTVA = #{marchebean.calculdetotaltravhtva()}</h3> <h3> Total TTC = #{marchebean.calculdetotaltravttc()} </h3> </f:facet> <p:column headerText="article" width="10%" > <h:outputText value="#{car.traveaux.article}"/> </p:column> <p:column headerText="Désignation des traveaux" width="40%" > <h:outputText value="#{car.traveaux.designation}"/> <h:outputText value="#{car.traveaux.paragraph}"/> </p:column> <p:column headerText="Unité"> <h:outputText value="#{car.traveaux.unite}"/> </p:column> <p:column headerText="PUHTVA"> <h:outputText value="#{car.prixunitaire}"/> </p:column> <p:column headerText="PUTTC"> <h:outputText value="#{marchebean.calcultva(car.prixunitaire)}" /> </p:column> <p:column headerText="Qtt"> <h:outputText value="#{car.quantite}"/> </p:column> <p:column headerText="MHTVA"> <h:outputText value="#{marchebean.calculmonthtva(car.prixunitaire ,car.quantite)}" /> </p:column> <p:column headerText="MTTC"> <h:outputText value="#{marchebean.calculmontttc(car.prixunitaire ,car.quantite)}" /> </p:column> </p:dataTable> </p:panel> </p:tab> </p:tabView> </h:form> </body> </ui:define> </ui:composition> 

 we need to provide the <f:facet name="header> <h:outputText value="aricle"/> </f:facet> then exporter will add the headers to your exported document. <p:column headerText="article" width="10%" > <f:facet name="header"> <h:outputText value="article" /> </f:facet> <h:outputText value="#{car.traveaux.article}"/> </p:column> 

这对我有用。 也许它需要validation,这就是为什么最后是空的。 添加immediate =“true”会跳过validation。

  <h:form id="confColaForm" .....> <p:dataTable id="tablacolas" ... > <f:facet name="header"> <h:commandLink id="exportar" update=":confColaForm:tablacolas" style="align:right;" immediate="true" > <h:graphicImage library="images" name="iconexcel.png" style="width:30px;height:30px; " title="Exportar" /> <p:dataExporter type="xls" target="tablacolas" fileName="ConfiguracionColas" /> </h:commandLink> </f:facet> ...(columns here) </p:dataTable/> </h:form> 

可能的原因可能是“managedbean范围”… 1)将范围更改为“查看”2)序列化managedbean

这对我工作