`

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;
}


}
分享到:
评论

相关推荐

    [primefaces]防止使用者重複執行報表1

    http://www.primefaces.org/showcase/ui/fileDownload.jsf](http://www.primefaces.org/showcase/ui/fileDownload.jsf) 是PrimeFaces官方的示例页面,展示了更多关于`p:fileDownload`组件的用法和配置。 通过上述...

    primefaces

    ### PrimeFaces:面向Java开发者的丰富UI组件库 #### 关于PrimeFaces PrimeFaces是一款功能丰富的JavaScript UI组件库...通过深入学习和掌握PrimeFaces组件的使用方法,你可以显著提高Web应用的开发速度和用户体验。

    PrimeFaces教程v0.5.doc

    例如,可以创建一个简单的 JSF 页面,使用 PrimeFaces 的 `&lt;p:outputLabel&gt;` 组件来显示一条问候消息。 **1.4 UI 组件** PrimeFaces 提供了多种类型的 UI 组件,涵盖布局、菜单、按钮、输入、输出等多种类别。下面...

    [報表] 使用UI查詢結果匯出pdf報表並自訂格式1

    生成的PDF内容被转换为`InputStream`,并通过`ExportUtil.genFile()`方法转化为可下载的文件对象,最后设置到`file`属性供`&lt;p:fileDownload&gt;`组件使用。 `auth_file_table_include.vm`是Velocity模板文件,它定义了...

    priceFaces学习

    这通常包括在JSF页面中添加一个基本的PrimeFaces组件,例如`&lt;p:button&gt;`,并在浏览器中运行查看效果。 **1.4 UI组件** PrimeFaces提供了大量的UI组件,这些组件覆盖了从简单的按钮到复杂的表格和图表等多种类型。...

Global site tag (gtag.js) - Google Analytics