前端页面
<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;
}
}
<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;
}
}