3

I am trying to export collection of dtos to excel with primefaces like this (the same as primefaces showcase demo, which is working).

<p:commandButton value="Export">
    <p:dataExporter type="xls" target="results" fileName="game_statistics" />
</p:commandButton>

I observed with firebug and it makes request, also the response looks like file content, but no file save/open dialog is popping. I am using mojarra 2.1.1 and tomcat 6 for app server.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user358448
  • 1,127
  • 3
  • 20
  • 39

4 Answers4

11

The <p:commandButton> sends by default an ajax request. You can't download files with ajax. Ajax is executed by Javascript, but Javascript has due to security restrictions no way to force a Save As dialogue and pass the ajax response to it.

You need to add ajax="false" to the component:

<p:commandButton value="Export" ajax="false">

Or just use a regular <h:commandButton>:

<h:commandButton value="Export">
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

Enclose it into <h:form>...</h:form> and it will work For example:

<h:form>
<p:commandButton value="Export">
    <p:dataExporter type="xls" target="results" fileName="game_statistics" />
</p:commandButton>
</h:form>
0

Primefaces doesn't support dynamic columns if you're using ones (by dynamic column I mean dynamic column attributes values). You can use POI for a workaround, but I don't know what exactly are you trying to do. Show us some code. What version of Primefaces are you using?

spauny
  • 4,976
  • 9
  • 44
  • 61
  • I use poi-3.2-FINAL, poi-scratchpad-3.2-FINAL,primefaces-2.2.1, jsf-api-2.1.1-b01, isf-impl-2.1.1-b01. ..... `code` ..... `code` – user358448 Oct 12 '11 at 08:01
  • Please edit/update your question by adding the full code there with `code formatting` – spauny Oct 12 '11 at 08:21
-2

I have a form page and I want to use filters from it and apply some validations before extracting data from the managed bean (jpa repository) when I click the commandButton, but the behavior of dataExporter it's to export the file right away, and then if I click again I get the right results, since the bean already worked on it at the first action...

Using the preProcessor option of dataExporter as a first step does the job, but I know it's not the right way to do this (should use for doc formatting etc), but I didn't find any other way to solve this (p.s. my case is for Export Page Data Only, not rendering the dataTable), does anyone have an alternative/solution for that?

bzani
  • 487
  • 4
  • 5
  • Preprocessor is in no way (100% sure) a solution for opening (or not) of a dialog – Kukeltje Dec 23 '19 at 17:50
  • _"does anyone have an alternative/solution for that?"_ sounds like a question... Belongs in a new question... – Kukeltje Dec 23 '19 at 18:50
  • it's the same situation as the question, except for the bean part not working properly... as I said, it works but it's not right to do, so I'm asking for an alternative... I don't get the downvotes anyway – bzani Dec 23 '19 at 19:52
  • Downvotes because of several reasons: 1: No code for a solution 2: No code related to **your** original problem that did not work, 3: No code related to the original question 4: cannot imagine (partly due to the missing code) that this is a solution for the problem, 5: so it is a hard to use solution to implement for others 6: I would not want others to try to implement this since it feels very hacky and might have just solved another invisible problem by e.g. getting a new fresh deploy.. – Kukeltje Dec 23 '19 at 20:48
  • as mentioned, it's the same situation, except for the bean part, so I have something like this: ` ` this doesn't work, unless if I use the `commandButton` action as a `preProcessor` in the `dataExporter`, it's not the right way but is the behavior I expected for the code above. – bzani Dec 24 '19 at 13:25
  • any suggestions would be appreciated. – bzani Dec 24 '19 at 13:29