Primefaces filedownload类实现错误

时间:2012-09-11 18:29:18

标签: primefaces download

当我在Primefaces UserGuide中实现primefaces FileDownload Class时,我的IDE显示set方法返回类型为void或更改为构造函数。

  

public FileDownloadController()

public class FileBean {

private StreamedContent file;

public FileDownloadController() {
InputStream stream = this.getClass().getResourceAsStream("yourfile.pdf");
file = new DefaultStreamedContent(stream, "application/pdf",
"downloaded_file.pdf");
}
public StreamedContent getFile() {
return this.file;
}
}

究竟是什么问题。

2 个答案:

答案 0 :(得分:3)

这是因为你的班级有不同的名字来解决这个改变

    public FileDownloadController() to public FileBean()

答案 1 :(得分:2)

将您的代码更改为此类..

package org.primefaces.examples.view;

 public class FileDownloadController {

private StreamedContent file;

public FileDownloadController() {        
    InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("/images/optimusprime.jpg");
    file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");
}

public StreamedContent getFile() {
    return file;
}  
}
相关问题