【问题标题】:Primefaces filedownload class implementation errorPrimefaces文件下载类实现错误
【发布时间】:2012-09-15 06:31:12
【问题描述】:

当我实现 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;
}
}

具体的问题是什么。

【问题讨论】:

  • public FileDownloadController() {改成public void FileDownloadController() {
  • 如果更改像您建议的 IDE 显示警告“更改为构造函数”
  • 请选择一个答案作为正确答案。

标签: primefaces download


【解决方案1】:

那是因为你的类有不同的名字,来解决这个变化

    public FileDownloadController() to public FileBean()

【讨论】:

    【解决方案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-05-18
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2013-04-12
      • 2015-11-18
      • 2013-05-11
      • 1970-01-01
      相关资源
      最近更新 更多