Data Exporter

ModelYearManufacturerColor
772e06f42006AudiOrange
25d305c01963RenaultWhite
704ac9372001BMWRed
c2de8bd61990MercedesRed
be7f15e21966JaguarGreen
a3ad69221995FordMaroon
923ee70c1980FordBrown
8863acbb1974OpelMaroon
fb4b25232008VolkswagenBrown
473f01331985BMWGreen

Export All Data
Export Page Data

Source

<p:dataTable id="tbl" var="car" value="#{tableBean.cars}" paginator="true" rows="10">
	<p:column>
		<f:facet name="header">
			<h:outputText value="Model" />
		</f:facet>
		<h:outputText value="#{car.model}" />
	</p:column>

	<p:column>
		<f:facet name="header">
			<h:outputText value="Year" />
		</f:facet>
		<h:outputText value="#{car.year}"/>
	</p:column>

	<p:column>
		<f:facet name="header">
			<h:outputText value="Manufacturer" />
		</f:facet>
		<h:outputText value="#{car.manufacturer}" />
	</p:column>

	<p:column>
		<f:facet name="header">
			<h:outputText value="Color" />
		</f:facet>
		<h:outputText value="#{car.color}" />
	</p:column>
</p:dataTable>
	
<h:panelGrid columns="2">
	<p:panel header="Export All Data">
		<h:commandLink>
			<p:graphicImage value="/images/excel.png" />
			<p:dataExporter type="xls" target="tbl" fileName="cars" />
		</h:commandLink>

		<h:commandLink>
			<p:graphicImage value="/images/pdf.png" />
			<p:dataExporter type="pdf" target="tbl" fileName="cars"/>
		</h:commandLink>
		
		<h:commandLink>
			<p:graphicImage value="/images/csv.png" />
			<p:dataExporter type="csv" target="tbl" fileName="cars" />
		</h:commandLink>
		
		<h:commandLink>
			<p:graphicImage value="/images/xml.png" />
			<p:dataExporter type="xml" target="tbl" fileName="cars" />
		</h:commandLink>
	</p:panel>
	
	<p:panel header="Export Page Data">
		<h:commandLink>
			<p:graphicImage value="/images/excel.png" />
			<p:dataExporter type="xls" target="tbl" fileName="cars" pageOnly="true"/>
		</h:commandLink>

		<h:commandLink>
			<p:graphicImage value="/images/pdf.png" />
			<p:dataExporter type="pdf" target="tbl" fileName="cars" pageOnly="true"/>
		</h:commandLink>
		
		<h:commandLink>
			<p:graphicImage value="/images/csv.png" />
			<p:dataExporter type="csv" target="tbl" fileName="cars" pageOnly="true"/>
		</h:commandLink>
		
		<h:commandLink>
			<p:graphicImage value="/images/xml.png" />
			<p:dataExporter type="xml" target="tbl" fileName="cars" pageOnly="true"/>
		</h:commandLink>
	</p:panel>
</h:panelGrid>