java - p:fileDownload 的问题(异常)
问题描述
Java 代码:
@ManagedBean(name="fileDownloadController")
@ViewScoped
public class MBfileDownloadController {
private StreamedContent file;
private List<File> listfiles=new ArrayList<File>();
private String fileName;
private String ruteGluster;
public MBfileDownloadController() throws NamingException {
Context context = new InitialContext();
ruteGluster = (String) context.lookup("java:/util/glusterFS");
if (ruteGluster.charAt(ruteGluster.length() - 1) != '/') {
ruteGluster = ruteGluster + "/";
}
File filestream=new File(ruteGluster + listfiles);
try {
file = new DefaultStreamedContent(new FileInputStream(filestream), new MimetypesFileTypeMap().getContentType(filestream));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<File> getListfiles() {
File folder = new File(ruteGluster + "reportesEstaticos/spools");
File[] listOfFiles = folder.listFiles();
listfiles=Arrays.asList(listOfFiles);
for(int i=0;i<listfiles.size();i++){
listfiles.get(i);
}
System.out.println("The List of file are" + listfiles);
return listfiles;
}
public void setListfiles(List<File> listfiles) {
this.listfiles = listfiles;
}
public String getFileName() {
getListfiles();
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public StreamedContent getFile() {
return this.file;
}
}
xhtml:
<h:dataTable value="#{fileDownloadController.listfiles}" var="x"
bgcolor="#F1F1F1" border="10" cellpadding="5"
cellspacing="3" first="0" rows="15" width="50%"
summary="This is a JSF code to create dataTable.">
<h:column>
<f:facet name="header">
<h:outputText value="Spools"></h:outputText>
</f:facet>
<h:commandLink value="#{x.name}">
<i class="fa fa-download" aria-hidden="true" style="width: 20px"></i>
<p:fileDownload value="#{fileDownloadController.file}" />
</h:commandLink>
</h:column>
</h:dataTable>
当我执行我的代码时,出现以下异常并且不下载文件,但表格显示文件并且表格很好。
解决方案
推荐阅读
- python - Python多继承超函数调定顺序
- react-native - 部分项目是否可以连续排列?
- c# - 在启动时验证 AutoMapper 配置
- pandas - 在 levenshtein distance/ Fuzz Score 上查找相似词
- pandas - pyspark groupby和window中的结构类型
- css - Wordpress:未从 CSS 加载 SVG 文件
- r - 将闪亮的变量传递给 data.table
- jquery-mobile - jquery mobile自定义选择失去对选择选项的关注
- vb.net - 我的 VB.Net 的 RDLC 中的 DateDiff 返回 #error
- jquery - 使用 Jquery 和 rails 交换图像的文本