0

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

公共文件下载控制器()

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

什么是确切的问题。

4

2 回答 2

3

那是因为你的班级有不同的名字,要解决这个变化

    public FileDownloadController() to public FileBean()
于 2012-09-14T22:24:35.473 回答
2

将您的代码更改为这样..

包 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;
}  
}
于 2012-09-14T22:31:12.177 回答