无法使用带有Action Tag的JSF PrimeFaces'FileDownload'下载文件

时间:2014-03-28 07:22:16

标签: jsf primefaces

我正在使用primefaces并希望使用文件下载功能和操作。当我使用actionListener它工作正常。但是当我使用动作时,它会在目标文件夹下载但不会在屏幕上显示。

在xhtml中

    <p:column>
        <p:commandButton id="calc" action="#{dFile.cpExportToExcel}" value=" Download "  ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"  >
             <p:fileDownload value="#{dFile.file}"/>  
        </p:commandButton>
    </p:column>

private StreamedContent file;

    getter and setter

        public String dFile(){
                FileOutputStream fileOut = null;
                String destination = ResBundleHelper.getFilePropertyValue("filedestination");
                 Workbook wb = new HSSFWorkbook();
                String filename="Files.xls";
                    try 
                    {
                        fileOut = new FileOutputStream(destination + filename);     
                        wb.write(fileOut);
                        fileOut.close();

                        java.io.InputStream inStream = new java.io.FileInputStream(destination + filename);
                         file = new DefaultStreamedContent(inStream, "application/vnd.ms-excel" , "FileToExport");  

返回“成功”;
 }                         catch(FileNotFoundException e)                         {                                                           返回“失败”;                             e.printStackTrace();

                    } 

       }

请帮助.....

0 个答案:

没有答案