primefaces 的下载功能,p:fileDownload的用法

前端页面
<p:dataTable id="patchfiledatatable" var="patch" value="#{patchBean.files}" dynamic="true"
emptyMessage="" paginator="true" rows="10" paginatorPosition="top">
<p:column >
<f:facet name="header">
<h:outputText value="查看" />
</f:facet>
<p:commandLink id="downloadLink" ajax="false">
<h:outputText value="下载"></h:outputText>
<f:setPropertyActionListener target="#{patchBean.selectFile}" value="#{patch}"></f:setPropertyActionListener>
<p:fileDownload value="#{patchBean.downLoadFile}"></p:fileDownload>
</p:commandLink>
</p:column>
</p:dataTable>

后台代码
public class TreeBean{
private List<PatchOutFile> files;
private StreamedContent downLoadFile;//下载要用
public List<PatchOutFile> getFiles() {
return files;
}
public void setFiles(List<PatchOutFile> files) {
this.files = files;
}
public StreamedContent getDownLoadFile() {
return downLoadFile;
}
public void setDownLoadFile(StreamedContent downLoadFile) {
this.downLoadFile = downLoadFile;
}
//取得files的代码(省略)

}

//封装展现的对象
public class PatchOutFile implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2666220076595535241L;

private String file;
private String path;
private StreamedContent downFile;
public PatchOutFile(){};
public PatchOutFile(String file,String path){
this.file = file;
this.path = path;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public StreamedContent getDownLoadFile() {
try {
InputStream stream = new FileInputStream(selectFile.getPath());

downLoadFile = new DefaultStreamedContent(stream, "DOS/PC - Pkzipped archive", selectFile.getFile());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return downLoadFile;
}
public void setDownFile(StreamedContent downFile) {
this.downFile = downFile;
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值