user358448
user358448

Reputation: 1187

Primefaces excel export is not working - no open/save dialog is shown

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.

Upvotes: 3

Views: 9347

Answers (4)

bzani
bzani

Reputation: 517

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?

Upvotes: -2

Daniyar Mukhtar
Daniyar Mukhtar

Reputation: 11

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>

Upvotes: 1

BalusC
BalusC

Reputation: 1108692

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">

Upvotes: 11

spauny
spauny

Reputation: 5096

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?

Upvotes: 0

Related Questions