如何停止jsf下载链接重装页面?

时间:2015-11-05 10:15:19

标签: jsf jsf-2

我通过使用h:datatable迭代对象列表来显示我的网页中的报告列表。这是

的代码
<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>
        ...

当我点击下载链接时(请参阅随附的屏幕截图),在下载文档之前,会重新加载网页并重新获取其报告列表。

下载链接的jsf代码如下所示

<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()方法代码:

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();

我无法弄清楚为什么会发生这种情况?有人可以帮助我理解这里的问题???

我的网页如下:Web page screenshot

0 个答案:

没有答案
相关问题