JSF Primefaces: Bug when exporting selected rows (excel, pdf)

3

I have a table on which I can select several rows using a checkbox that would be the column selector :

<p:dataTable    value="#{cityBean.cities}" var="city" id="dt_cities" widgetVar="w_cities"
                filteredValue="#{cityBean.filteredCities}"
                selection="#{cityBean.selectedCities}" 
                rowKey="#{city.id}"
                rowSelectMode="add"
                scrollable="true" scrollHeight="300">
    <p:column id="selector" selectionMode="multiple" style="text-align:center" />
    <p:column headerText="Name" sortBy="#{city.name}" filterBy="#{city.name}"  filterMatchMode="contains">
        <h:outputText value="#{city.name}" />
    </p:column>
</p:dataTable>

Then I have two buttons with which I can export the selected rows (using selectionOnly="true" ) in two ways: XLS or PDF .

<h:commandLink >
   <p:graphicImage url="#{resource['icons/excel_exports.png']}" />
   <p:dataExporter type="xls" target="dt_cities" fileName="list_cities" selectionOnly="true" />
</h:commandLink>
<h:commandLink>
   <p:graphicImage url="#{resource['icons/pdf_exports.png']}" />
   <p:dataExporter type="pdf" preProcessor="#{cityBean.pdfLandscape}" 
                            target="dt_cities" fileName="list_cities" 
                            selectionOnly="true"/>
</h:commandLink>

The bug with which I find myself is that for example: I have a list of 10 elementos numbered% of 1 al 10 , I select the elements 9, 8, 5 y 2 . When clicking on the export buttons, 4 elementos appears but they do not correspond to your selection, the 1, 2, 3 y 4 elements appear.

Recognizes how many elements are selected but can not interpret what they are.

I am currently using: JSF 2.2 and Primefaces 5.1 RC1 .

    
asked by Ralsho 25.10.2016 в 13:54
source

2 answers

2

Probably a bug typical of Primefaces 5.1.

For the case of export to PDF :

I suggest you add primefaces-extensions 3.0.0 to your project, which is the version compatible with Primefaces 5.1 . If you use Maven this would be like this:

<dependency>
    <groupId>org.primefaces.extensions</groupId>
    <artifactId>primefaces-extensions</artifactId>
    <version>3.0.0</version>
</dependency>

In your XHTML add the following namespace:

xmlns:pe="http://primefaces.org/ui/extensions" 

... and on your button, instead of using p:dataExporter , use pe:exporter .

<h:commandLink>
   <p:graphicImage url="#{resource['icons/pdf_exports.png']}" />
   <pe:exporter type="pdf" preProcessor="#{cityBean.pdfLandscape}" 
                            target="dt_cities" fileName="list_cities" 
                            selectionOnly="true"/>
</h:commandLink>

The pe:exporter tag allows you to also export to Excel , but only does it towards XLSX and not XLS . . p>     

answered by 25.12.2016 в 02:31
1

Add a column and check that the id of each city field is unique. For example:

<p:column id="cityId" value="#{city.id}" />
    
answered by 17.11.2016 в 14:27