【发布时间】:2014-04-22 08:30:09
【问题描述】:
我在JSF 页面中有一个ADF 表,该表绑定到View Object,其中包含用户上传的文件。这个View Object 包含下载文件所需的所有信息,例如blob domain、file type 和file name。每一行都有一个下载按钮,用户可以通过它下载选定的文件。
每件事都是第一次完美运行。问题是当用户按下他/她已经下载的某些文件的下载按钮时,文件会损坏。该文件出现在浏览器的下载部分,但是当我尝试打开它时,它告诉我无法打开该文件,因为不支持文件格式或文件扩展名。
这是JSF页面中的按钮:
<af:column id="c31">
<af:commandButton text="Download" id="cb12" partialSubmit="true">
<af:fileDownloadActionListener method="#{ITDetalisBean.downloadSelectedFile}"
filename="#{row.FileName}" contentType="#{row.FileType}"/>
</af:commandButton>
</af:column>
如您所见,按钮位于<af:column> 标记中。所以每个文件行都有对应的下载按钮。
这里是Bean 方法:
public void downloadSelectedFile(FacesContext facesContext, OutputStream outputStream)
{
// get the view object from the application module
AppModuleImpl appM = (AppModuleImpl)(JSFUtils.getApplicationModule("AppModuleDataControl"));
ViewObject fileUploadedVO = appM.findViewObject("UplodedFilesViewTransient1");
// get the file content as blob domain from the current row
BlobDomain blobDomain=(BlobDomain)fileUploadedVO.getCurrentRow().getAttribute("FileContn");
// download the file using output stream
try {
HttpServletResponse response =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
InputStream in = blobDomain.getBinaryStream();
outputStream = response.getOutputStream();
byte[] buf = new byte[1024];
int count;
while ((count = in.read(buf)) >= 0) {
outputStream.write(buf, 0, count);
}
in.close();
outputStream.flush();
outputStream.close();
facesContext.responseComplete();
} catch (IOException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
【问题讨论】:
标签: java jsf oracle11g download oracle-adf