我正在尝试使用 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 这样。