Alright, I have basically killed Google searching for a solution.
Using richfaces and JSF.
Basically I have a h:commandButton that prints a report once clicked, but if you click it more than once the DownloadUtils.download() method gets interrupted and then it breaks. I need to avoid that.
I have tried to disable "onclick". I have tried to disable using a time out - solutions found here: Disable `<h:commandButton>` after clicked, but action should be fired
But those basically either doesnt fire the action at all, or it gets to a point during the download and then stops. It doesnt return anything, so no report gets downloaded.
You can't use ajax based buttons/links because of the download.
Links to confirm a4j limitation here: https://community.jboss.org/thread/8598 Downloading a CSV file using JSF
I have also thought of trying to add a popup panel after the button is clicked without using ajax like this: http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=popup&skin=blueSky
But again it doesnt continue with the download at some point (usually after it prints the XML in my log).
Any ideas welcome, any solution will do at this moment, even redirecting after to a new page.
Button
<h:commandButton action="#{managingBean.download()}" value="#{bundle.download}"/>
Managing Bean
DownloadUtils.download(object.getOrderReference() + ".pdf",
service.getReport(ReportFormat.PDF, object.getOrder()));
Service
public InputStream getReport(ReportFormat format, Object object) throws IOException {
InputStream is = getReportResource("String", format);
Report report = someService.createReport(object);
Document doc = toXml(report, Report.class);
Map<String, Object> params = new HashMap<String, Object>();
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, doc);
params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd'T'HH:mm:ss");
return getReportFromJasper(is, params, format, true, true, false);
}
Thank you in advance.