2014-11-06 83 views
0

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

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

的可能重复[能否” t导出数据表从excel jsf页](http://stackoverflow.com/questions/23217879/cant-export-data-table-to-excel-from-jsf-page) – 2014-11-06 14:04:31

+0

@EmilKaminski:谢谢你的回应我的问题是不同的,我有exel文件中的空列,虽然我改变了值到列同样的错误仍然存​​在! – BELLIL 2014-11-06 14:29:29

+0

尽量缩小问题范围。在任何面板和选项卡之外创建一个简单的数据表,并查看它是否有效?如果是,请添加更多列......如果仍然有效,请尝试继续工作,直到您发现问题。 – 2014-11-07 07:16:44

回答

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

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

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

请通过解释什么是不同的以及为什么 – Kukeltje 2015-09-01 21:17:59

+0

@Kukeltje树有点不同,并尝试添加immediate =“true”来改进您的答案。可能它失败了,因为它需要一些验证,并跳过它。我会将其添加到我的主要评论。 – 2015-09-04 08:36:00

0

可能的原因可能是 “managedbean范围” ...... 1)的变化范围为 “视图” 2)序列managedbean

这个工作对我来说