can someone tell me is it possible to get p:fileDownload work on ajax request?
I need this because I need to control ajax status :
onstart .. show ajaxloadingbar.gif
onerror .. show error in growl
onsuccess .. hide ajaxloader.gif, and write success message in growl
Right now, code below work well, but when user click on button, there is no some indicator that showing him "Generating report is in progress .. please wait", or "Error while generating report ..."
If I remove ajax tag, then p:filedownload doesn't work .. but report is generated on server side.
Can some one help me with this?
This is snippet of code:
report.xhtml
Code: Select all
<p:commandButton value="Report" title="Report" styleClass="reportButton" actionListener="#{servis.generateReport}" ajax="false" >
<p:fileDownload contentDisposition="inline" value="#{servis.report}" />
</p:commandButton>
Servis.java
Code: Select all
@ManagedBean(name = "servis")
@RequestScoped
public class Servis
{
private StreamedContent report;
public StreamedContent getReport() throws FileNotFoundException {
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
File result = new File(extContext.getRealPath("//resources//reports//pdf//test1.pdf"));
InputStream reportStream = new FileInputStream(result.getAbsolutePath());
return new DefaultStreamedContent(reportStream, "application/pdf; charset=UTF-8", "test1.pdf");
}
public void setReport(StreamedContent report) {
this.report = report;
}
public void generateReport(ActionEvent ae)
{
HashMap parameterMap = new java.util.HashMap();
parameterMap.put("id_tipa", this.id_tipa);
db.report2Pdf("/home/user_name/Projects/java/jsf/testJSF_5/web/resources/reports/jasper/test1.jasper", "/home/user_name/Projects/java/jsf/testJSF_5/build/web/resources/reports/pdf/test1.pdf", parameterMap);
}