2013-04-18 16 views
12

シンプルなファイルダウンロードをしようとすると、私はAJAXステータスバーがぶら下がっているだけです。私のバッキングビーン出力は、prepとダウンロードに正しい名前を表示します。Primefaces Fileダウンロードが動作しません。

これは間違っていますか?両方の出力が正しいと思われます。

JSF 2.0 Primefaces 3.4

 <h:form> 
      <p:commandButton id="downloadLink" value="Download" actionListener="#{filemanagement.prepDownload}"> 
       <p:fileDownload value="#{filemanagement.download}" /> 
      </p:commandButton> 
     </h:form> 

バッキングBean:

private DefaultStreamedContent download; 

public void setDownload(DefaultStreamedContent download) { 
    this.download = download; 
} 

public DefaultStreamedContent getDownload() throws Exception { 
    System.out.println("GET = " + download.getName()); 
    return download; 
} 

public void prepDownload() throws Exception { 
    File file = new File("C:\\file.csv"); 
    InputStream input = new FileInputStream(file); 
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); 
    setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName())); 
    System.out.println("PREP = " + download.getName()); 
} 

答えて

20

あなたはPrimeFacesのcommandButtonとのcommandLinkを使用したい場合は、Primefaces Documentation 6.1

を参照してくださいとしてのAjaxオプションを無効にします fileDownloadには、ページ全体をリフレッシュする必要がありますファイルを送信しました。コマンドボタンの内側

<h:form> 
    <p:commandButton id="downloadLink" value="Download" ajax="false" actionListener="#{filemanagement.prepDownload}"> 
    <p:fileDownload value="#{filemanagement.download}" /> 
    </p:commandButton> 
</h:form> 
+0

おかげ - ダウンロード(FF 17)の入力を要求しませんでした。しかし、この情報に感謝する(それを逃した)。 – user2124871

+0

ファイル管理Beanのスコープは? – Manuel

+0

セッション - ビュー自体には3つのフォームがあります。それらのどれもが混ざり合っていません。私はPrimefaceを読んでいて、複数の書式をスケッチにすることができます。 – user2124871

10

、設定アヤックス=偽とのcommandLinkのアクションまたはアクションリスナーを使用しないでください。

<h:form> 
    <p:commandButton id="downloadLink" value="Download" ajax="false"> 
    <p:fileDownload value="#{filemanagement.prepDownload}" /> 
    </p:commandButton> 
</h:form> 

豆:

public StreamedContent prepDownload() throws Exception { 
    StreamedContent download=new DefaultStreamedContent(); 
    File file = new File("C:\\file.csv"); 
    InputStream input = new FileInputStream(file); 
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); 
    download = new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName())); 
    System.out.println("PREP = " + download.getName()); 
    return download; 
} 
関連する問題