1

I am using PrimeFaces 5 and using dataexporter to export .xls and pdf file. When i click on export, nothing seems to be happening. Below is my code:

<h:body>
    <h:form id="formReport">
        <ui:include src="menu.xhtml"></ui:include>
             <p:dataTable id="ngoReporttbl" var="obj" styleClass="datatable"
                    value="#{ngoReportController.ngoReportList}" >

                    <f:facet name="header">
                      List of Cars
                        <p:commandButton id="toggler" type="button" value="columns" style="float:right" icon="ui-icon-calculator"></p:commandButton>
                        <p:columnToggler datasource="ngoReporttbl" trigger="toggler"></p:columnToggler>
                    </f:facet>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="NGO Id"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{obj.ngoId}"></h:outputText>
                    </p:column>
                        <p:column>
                        <f:facet name="header">
                            <h:outputText value="NGO Name Org"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{obj.ngoNameOrg}"></h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Environment"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{obj.environment}"></h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Livelihood"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{obj.livelihood}"></h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Country"></h:outputText>
                        </f:facet>
                        <h:outputText value="#{obj.country}"></h:outputText>
                    </p:column>
                </p:dataTable>  

                <h:commandLink style="float:right">
                    <p:graphicImage  value="../images/pdf.png" width="45"></p:graphicImage>
                   <p:dataExporter type="pdf" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
                 </h:commandLink>
                 <h:commandLink style="float:right">
                    <p:graphicImage  value="../images/csv.png" width="45"></p:graphicImage>
                   <p:dataExporter type="xls" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
                 </h:commandLink>

        <ui:include src="footer.xhtml"></ui:include>
    </h:form>
</h:body>

Both the dataTable and the Export command are within one form. It is similar to the example given on primefaces.org site. But, I'm unable to export data to pdf, cvs.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Do you have the itext library installed? – Emil Kaminski Jul 08 '14 at 08:55
  • No.. why is that needed in case of primefaces? – Hardik Agarwal Jul 08 '14 at 09:32
  • Primefaces is only a component library for JSF. It does not posses the abilities to create PDF files itself. From the PF documentation: "DataExporter is nested in a UICommand component such as commandButton or commandLink. For pdf exporting itext and for xls exporting poi libraries are required in the classpath." – Emil Kaminski Jul 08 '14 at 12:45

1 Answers1

2

For XLS, you don't need anything extra. For PDF, you need POI. Primefaces only works with 2.1.7 due to licensing issues. And your commandButton / commandLink need to be ajax="false". Good luck.

William Ng
  • 21
  • 2