0

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

Hemachandra
  • 69
  • 2
  • 14
  • That behavior is only possible with JavaScript, but this isn't visible in the information provided so far. So I guessed that you just misinterpreted the log/behavior. – BalusC Nov 05 '15 at 10:35
  • ok. But I am not using any javascript here. For getting list of reports, I am calling Controller.ReportsList() which returns arrayList. For downloading specific report, I am calling Controller.downloadReport() method which writes data to response. When I click on download link, I am able to see ReportsList() method logs before downloadReport() logs. – Hemachandra Nov 05 '15 at 11:22
  • So, just only because a getter method is invoked, you assumed that this means that the whole page is reloaded? You thus didn't check the HTTP request/response payload and actual browser behavior at all to confirm if the whole page is reloaded? I think your definiton of "page is reloaded" is completely wrong. – BalusC Nov 05 '15 at 11:49
  • I am using rest to get the data in bean methods. I didn't see any problem with rest fetching data and assigning to response. So, I thought it might be problem with my logic in jsf. I will check that once again. Anyway, Thank you so much for your suggestions @BalusC. – Hemachandra Nov 06 '15 at 06:28
  • So, you're doing business logic in getter methods? Just stop doing that. – BalusC Nov 06 '15 at 07:02

0 Answers0