I am showing list of reports in my web page by iterating list of objects using h:datatable. Here is the code for that
<p:dataTable emptyMessage="#{msg.reports_message}" var="fileData" value="#{Controller.ReportsList}" resizableColumns="true" scrollable="true" style="width:1300">
<p:column id="reporttype" style="width:75px">
<f:facet name="header"><h:outputText value="#{msg.reports_type}" styleClass="datatable-header" /></f:facet>
<h:outputText value="#{fileData.reportType}" styleClass="datatable-data" />
</p:column>
<p:column id="reportname" style="width:75px">
<f:facet name="header"><h:outputText value="#{msg.reports_name}" styleClass="datatable-header" /></f:facet>
<h:outputText value="#{fileData.reportName}" styleClass="datatable-data" />
</p:column>
...
When I click on download link(plz refer attached screenshot), Before document is getting downloaded, webpage is reloaded and its fetching list of reports again.
jsf code for download link looks like below
<p:column id="download" style="width:50px">
<h:commandLink id="downloadLink" rendered="#{Bean.reportStatus == 'COMPLETE'}" actionListener="#{Controller.downloadReport}">
<h:outputText value="#{msg.reports_download}" styleClass="datatable-data" />
<f:param name="downloadkey" value="#{Bean.reportKey}"></f:param>
</h:commandLink>
</p:column>
downloadReport() method code:
in = new BufferedInputStream( conn.getInputStream());
byte[] b = new byte[1024];
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();ec.responseReset();
ec.setResponseContentType("text/csv");
ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + "Report_"+currentTime+".csv" + "\"");
outputStream = ec.getResponseOutputStream();
while(in.read(b) != -1){
outputStream.write(b);
outputStream.flush();
}
FacesContext.getCurrentInstance().responseComplete();
I am not able to figure it out why its happening like that??? Can somebody plz help me in understanding the issue here???
My web page looks like: Web page screenshot