【问题标题】:Primefaces fileDownload JavaScript ErrorPrimefaces 文件下载 JavaScript 错误
【发布时间】:2012-05-18 17:18:02
【问题描述】:

我正在尝试使用 Primefaces fileDownload 组件下载文件。不幸的是,它不起作用。我只收到一个 Javascript 错误“[window] 响应不包含 XML 数据”

我使用 JSF 2.1.6 和 Primefaces 3.2,IceFaces Push 2.0.2 版用于推送数据,以及一些 Spring Functions 和 Spring 3.1.0 版。全部运行在 Tomcat 6.0.33 上。

我的 xHtml 代码片段

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
<h:body>
 <p:layout> 
   ...
   <p:layoutUnit id="east" ... >
     <h:form id="eForm">
       <p:dataTable ... >
         ...
           <p:row >
             <p:column style="font-weight: bold;">Attach 1:</p:column>
               <p:column>
                 <p:commandLink id="attach1" value="Download" ajax="false" immediate="true">
                      <p:fileDownload value="#{data.file}" />
                    </p:commandLink> 
                  </p:column>
                </p:row>
       </p:dataTable>
     </h:form>
    ...
 </p:layout>
</h:body>

文件下载 Bean

@ManagedBean(name = "data")
@RequestScoped
public class FileDownload {

private StreamedContent file;

public FileDownload() {
    InputStream stream = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("/resources/images/phone_speaker_x24.png");
    file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");
}

public StreamedContent getFile() {
    return file;
}
}

FireBug 的错误

 [window] the response does not contain XML data  bridge...9208334 (Zeile 1217)
 [window] Error [status: emptyResponse code: 200]: An empty response was received from the server. Check server error logs.

Tomcat 日志中没有错误

编辑

Icefaces 是问题所在。删除所有 Icefaces Libs 下载工作正常。但是没有 IceFaces 就没有 Push 所以。

【问题讨论】:

    标签: jsf primefaces icefaces


    【解决方案1】:

    好吧,Primefaces 和 IcePush 并不总是一起工作。从我的项目中删除 IceFaces Push 使下载工作但没有推送。

    所以我决定自己编写 Push 并且只使用 Primefaces。

    【讨论】:

      【解决方案2】:

      如果在 getFile 方法中设置断点,file==null 吗?

      问题可能是你的课程结构不好

      【讨论】:

      • File != null,所以这不是问题
      猜你喜欢
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 2015-11-18
      • 2013-05-11
      相关资源
      最近更新 更多