Exporter still broken (exportFunction)

Community Driven Extensions Project
Hamsterbau
Posts: 401
Joined: 28 Dec 2011, 17:44

26 Sep 2017, 13:16

Hi,

i am still facing issues with exporter. It is a littble bit akward but it depends on the usage of the exporter:
  • Excel-Exporter works
  • PDF-Exporter only works for selectionOnly=false
  • PDF-Exporter failed for selectionOnly=true
I used the following EL to export specific data:

Code: Select all

<p:column ... exportFunction="#{entry.getName()}" />
I have to use entry.getName() because normal EL (entry.name) is not working at all.
In PDF case with selectionOnly=true the following stacktrace (shortended) appears:

Code: Select all

11:08:40,964 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-85) //.../mySite.xhtml @116,124 exportFunction="#{entry.getName()}": Method not found: class java.util.ArrayList.getName(): javax.el.MethodNotFoundException: //.../mySite.xhtml @116,124 exportFunction="#{entry.getName()}": Method not found: class java.util.ArrayList.getName()
	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
	at org.primefaces.extensions.component.exporter.Exporter.exportColumnByFunction(Exporter.java:87)
	at org.primefaces.extensions.component.exporter.PDFExporter.addColumnValue(PDFExporter.java:838)
	at org.primefaces.extensions.component.exporter.PDFExporter.exportCells(PDFExporter.java:691)
	at org.primefaces.extensions.component.exporter.PDFExporter.exportSelectionOnly(PDFExporter.java:355)
	at org.primefaces.extensions.component.exporter.PDFExporter.exportPDFTable(PDFExporter.java:243)
	at org.primefaces.extensions.component.exporter.PDFExporter.export(PDFExporter.java:134)
	at org.primefaces.extensions.component.exporter.DataExporter.processAction(DataExporter.java:196)
	at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
Can you fix this?

Thanks in advance,

Daniel

PS: It would be nice to be able to just use EL instead of a explicit method that must be implemented in a bean.
Primefaces 6.1.8 (PF Extensions 6.1.5)
JSF: Mojarra 2.2 (Spec 2.2) - running on WildFly 10.1.0.Final

Melloware
Posts: 1474
Joined: 22 Apr 2013, 15:48

26 Sep 2017, 13:29

A couple of notes, the exportFunction is implemented by PF and PFE is just extending it so I can't fix the use of the EL Expression. I believe it has to be a function call the way it is designed.

Second, I will look into the PDF issue.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 7.0.8 / PF Extensions 7.0.3

Melloware
Posts: 1474
Joined: 22 Apr 2013, 15:48

26 Sep 2017, 13:44

I just tested this an it works fine. On the PFE Showcase in the Multiple tables Example I changed the table to the following.

Code: Select all

	<p:dataTable id="messageTable" var="message" value="#{messageTableController.messages}" paginator="true" rows="5"
		paginatorPosition="bottom" filteredValue="#{messageTableController.filteredMessages}" 
		selectionMode="single" selection="#{messageTableController.selectedMessage}" rowKey="#{message.time}">
The first column I used an Exporter function...

Code: Select all

<p:column filterBy="#{message.subject}" exportFunction="#{messageTableController.exportColumn}">
			<f:facet name="header">
				<h:outputText value="Subject" />
			</f:facet>
			<h:outputText value="#{message.subject}" />
</p:column>
My java code i implemented the exportColumn function as...

Code: Select all

    public String exportColumn(final UIColumn column) {
        return "PFE Rocks!";
    }
I set the exporter to selectionOnly="true".

Code: Select all

<pe:exporter type="pdf" target="messageTable,messageDetailsTable" fileName="MessagesAndDetails" datasetPadding="4" selectionOnly="true"/>
When I export the PDF and XLS sheet only my single selected row is printed out in the PDF and the XLSX.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 7.0.8 / PF Extensions 7.0.3

Hamsterbau
Posts: 401
Joined: 28 Dec 2011, 17:44

26 Sep 2017, 18:37

First, yepp you are completly right :)

Second, thanks a lot for your answers. But your example only used the specific method with UIColumn as parameter. I tried accessing data directly from table var instance, what works in most cases like mentioned above.

But perhaps i should implement for each column a separate method, what is a little bit messy, but should work. But still akward that my mentioned try only fails for PDF with selectionOnly=true

Have a nice day,

Daniel

Edit: Another difference to my tests is the selection mode - i used multiple. But i will try the extra method tomorrow and hope this will work :roll:
Primefaces 6.1.8 (PF Extensions 6.1.5)
JSF: Mojarra 2.2 (Spec 2.2) - running on WildFly 10.1.0.Final

Melloware
Posts: 1474
Joined: 22 Apr 2013, 15:48

26 Sep 2017, 18:59

Yeah every example I have seen from PF they are using the (UI Column) method. I didn't even know your method worked until you told me!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 7.0.8 / PF Extensions 7.0.3

Hamsterbau
Posts: 401
Joined: 28 Dec 2011, 17:44

28 Sep 2017, 14:56

Ok, it is still weird. After debugging the code i found out, what caused me so much trouble. PDFExporter and ExcelExporter using different code snippets to check for used selection type:

PDFExporter:

Code: Select all

    protected void exportSelectionOnly(FacesContext context, DataTable table, PdfPTable pdfTable) {
        Object selection = table.getSelection();
        String var = table.getVar();
        if (selection != null) {
            Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
            if (selection.getClass().isArray()) {
               ...
            } else {
               ...
ExcelExporter

Code: Select all

    protected void exportSelectionOnly(FacesContext context, DataTable table, Sheet sheet) {
        Object selection = table.getSelection();
        String var = table.getVar();
        if (selection != null) {
            Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
            if (selection.getClass().isArray()) {
                ...
            } else if (List.class.isAssignableFrom(selection.getClass())) {
               ...
So with PDFExporter selection must be an array. ExcelExporter on the other hand also accepts Lists. My choice would be, to have List support in both cases, but i would recommand following code snippet:

Code: Select all

Collection.class.isAssignableFrom(selection.getClass());
Would be more robust to changes of selection "lists".

Wbr,

Daniel
Primefaces 6.1.8 (PF Extensions 6.1.5)
JSF: Mojarra 2.2 (Spec 2.2) - running on WildFly 10.1.0.Final

Melloware
Posts: 1474
Joined: 22 Apr 2013, 15:48

28 Sep 2017, 15:25

Let me make that change and do a SNAPSHOT build for you. I will post back here when the SNAPSHOT is ready.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 7.0.8 / PF Extensions 7.0.3

Hamsterbau
Posts: 401
Joined: 28 Dec 2011, 17:44

28 Sep 2017, 15:56

Thanks for your effort. But perhaps i should use the described way to use my own custom exporter:
https://www.primefaces.org/showcase-ext ... porter.jsf

Nevertheless, Primefaces and PF Extensions are really great :)

Thanks for all your work!

PS: Workaround is using arrays instead of Lists.
Primefaces 6.1.8 (PF Extensions 6.1.5)
JSF: Mojarra 2.2 (Spec 2.2) - running on WildFly 10.1.0.Final

Melloware
Posts: 1474
Joined: 22 Apr 2013, 15:48

28 Sep 2017, 18:45

Well I created this issue: https://github.com/primefaces-extension ... issues/493

And created a SNAPSHOT: https://oss.sonatype.org/content/reposi ... -SNAPSHOT/

PDF and Excel should have been at least doing the same consistent handling so that is a bug either way!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 7.0.8 / PF Extensions 7.0.3

tom_t
Posts: 17
Joined: 01 Apr 2016, 21:36

26 Oct 2017, 18:53

I am also having some problems with Exporter ever since I moved to PF 6.1.6 from 6.1.2. I am on Extensions 6.1 The export to Excel worked previously. I now get this error:

FATAL: org.apache.poi.ss.usermodel.Font.setBoldweight(S)V
java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Font.setBoldweight(S)V
at org.primefaces.extensions.component.exporter.ExcelExporter.createCustomFonts(ExcelExporter.java:985)
at org.primefaces.extensions.component.exporter.ExcelExporter.export(ExcelExporter.java:110)
at org.primefaces.extensions.component.exporter.DataExporter.processAction(DataExporter.java:177)

I am using these jars:

poi 3.1.6
poi-ooxml 3.1.6
poi-ooxml-schemas 3.1.6

(This is a Maven project)

.. and my Java class is referencing XSSFWorkbook, XSSFSheet, XSSFRow, XSSFCell

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests