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

user358448 picture user358448 · Oct 11, 2011 · Viewed 8.2k times · Source

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.

Answer

BalusC picture BalusC · Oct 12, 2011

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