I have a PrimeFaces DataTable and I want to use DataExporter to export only selected rows.
Code: Select all
<p:dataTable id="usersTbl" var="user" value="#{adminController.users}"
rowKey="#{user.id}" paginator="true" rows="10"
selectionMode="multiple" selection="#{adminController.selectedUsers}" >
<p:column>
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<h:outputText value="#{user.emailId}" />
</p:column>
</p:dataTable>
Code: Select all
<h:commandLink>
<p:graphicImage value="/resources/images/excel.png"/>
<p:dataExporter type="xls" target="usersTbl" fileName="users" selectionOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/resources/images/pdf.png"/>
<p:dataExporter type="pdf" target="usersTbl" fileName="users" selectionOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/resources/images/csv.png"/>
<p:dataExporter type="csv" target="usersTbl" fileName="users" selectionOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/resources/images/xml.png"/>
<p:dataExporter type="xml" target="usersTbl" fileName="users" selectionOnly="true"/>
</h:commandLink>
1)If selectedUsers is of type List<User>, when I click on Export (XLS/PDF/CSV/XML) I am getting NumberFormatException for input string "id".
2)If I change the selectedUsers variable type to User[] then Export to XML and PDF are working fine.
But for CSV I am getting all the selected rows data in a single row.
For XML I am getting all the selected rows data in a single <usersTbl> tag instead of separate <user> tag wrapped for each user row.
Any work around for this?