user3442674
user3442674

Reputation: 23

Primefaces data exporter

I am using p:dataExporter to export the data to client machine. It creates a file in given format based on the data from table mentioned in the tareget method. On export button click file would be exported to client machine.This all goes fine. Now I want to provide an 'open' button to let open the file with/without downloading the file to client machine. p:dataExporter dont have such property. Does JSF provide such property or any other component recommended?

Here is my code sample,

<p:dataExporter type="#{applicationFilterBean.exportFileType}" target=":appForm:appTable"
                            fileName="#{applicationFilterBean.exportFileName}" />

Upvotes: 1

Views: 1388

Answers (2)

user3442674
user3442674

Reputation: 23

Thanks for your suggestion Michele, I have created my customExport class. The only change needed was to change responseHeader to Content-Disposition-inline,

response.setHeader("Content-disposition", "inline;filename="+ fileName + ".pdf");

This is working absolutely fine.

Upvotes: 1

Michele Mariotti
Michele Mariotti

Reputation: 7459

no it is not possible because content-disposition is hardcode.

for example, look through org.primefaces.component.export.PDFExporter source code:

protected void writePDFToResponse(ExternalContext externalContext, ByteArrayOutputStream baos, String fileName) throws IOException, DocumentException {     
    externalContext.setResponseContentType("application/pdf");
    externalContext.setResponseHeader("Expires", "0");
    externalContext.setResponseHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
    externalContext.setResponseHeader("Pragma", "public");
    externalContext.setResponseHeader("Content-disposition", "attachment;filename="+ fileName + ".pdf");
    externalContext.setResponseContentLength(baos.size());
    externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", Collections.<String, Object>emptyMap());
    OutputStream out = externalContext.getResponseOutputStream();
    baos.writeTo(out);
    externalContext.responseFlushBuffer();
}

maybe some other library provide this feature, otherwise you should develop your own DataExporter.

Upvotes: 0

Related Questions