Reputation: 182
I am trying to export a data table to excel using primefaces 5.1, poi 3.9. My xhtml code is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputStylesheet library="css" name="custom.css" />
<h:outputScript library="js" name="customjs.js" />
</h:head>
<h:body>
<h:form id="form">
<h:form>
<p:dataTable id="tbl" var="tempEmployeeInOut"
value="#{tempInOut.tempEmployeeInOuts}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
paginator="true" rows="10" style="margin-bottom:20px">
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage library="images" name="excel.png" width="24" />
<p:dataExporter type="xls" target="tbl" fileName="tempEmployeeInOut" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="pdf.png" width="24" />
<p:dataExporter type="pdf" target="tbl" fileName="tempEmployeeInOut" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="csv.png" width="24" />
<p:dataExporter type="csv" target="tbl" fileName="tempEmployeeInOut" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="xml.png" width="24" />
<p:dataExporter type="xml" target="tbl" fileName="tempEmployeeInOut" />
</h:commandLink>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Employee Id" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.empID}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Entry Date" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.entryDate}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Morning In Time" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.morInTime}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Lunch Out Time" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.lunchOutTime}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Lunch In Time" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.lunchInTime}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="OutTime" />
</f:facet>
<h:outputText value="#{tempEmployeeInOut.outTime}" />
</p:column>
</p:dataTable>
<h3>Export Page Data Only</h3>
<h:commandLink>
<p:graphicImage library="images" name="excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="pdf.png" />
<p:dataExporter type="pdf" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="csv.png" />
<p:dataExporter type="csv" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="xml.png" />
<p:dataExporter type="xml" target="tbl" fileName="cars"
pageOnly="true" />
</h:commandLink>
</h:form>
</h:form>
</h:body>
</html>
I have nothing special in my TempInOut class. I am able to display my data into the data table. But when I am clicking the export to excel icon or any other icon, nothing is happening except the url have one # appended. I searched at many places but mostly there were version issue. I am not able understand where I am doing wrong.
my data table looks something like this.
Upvotes: 0
Views: 7462
Reputation: 729
Did you add Apache POI dependecies?
If not,
you download the latest stable version from Apache POI download page, extract downloaded file, put library in /WEB-INF/lib
folder and re-run webapp on server.
Or if you're using Maven, copy and paste this dependecies on you pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
Upvotes: 2