2013-04-18 25 views
12

Basit bir dosya indirmeye çalışıyorum çalışıyorum ve tek alıyorum, asılı bir AJAX durum çubuğu ve işte bu. Yedek fasulye çıkışlarım, hazırlık ve indirme işleminde doğru adı verir.Primefaces Dosya İndirme çalışmıyor mu?

Bunu yanlış mı yapıyorum? Her iki çıktı da doğru görünüyor.

MTU 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> 

yedekleme fasulye:

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

cevap

20

Eğer PrimeFaces KomutDüğmesi'ı ve commandLink kullanmak isterseniz, Primefaces Documentation 6.1

Bkz olarak ajax seçeneği devre dışı fileDownload, önceden tam sayfa yenilemesi gerektirir dosyayı gönderdi. Komut düğmesinin İçinde

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

Teşekkürler - Bir indirme (FF 17) için istemi yoktu. Ama bu bilgiyi takdir et (kaçırdı). Filiz çekirdekli fasulyenin – user2124871

+0

kapsamı? – Manuel

+0

Oturum - Görünümün kendisinde 3 form var. Hiçbiri birbirinin içine girmedi. Primefaces ve çoklu formların taslak olabileceğini okudum. – user2124871

10

, set ajax = false ve commandlink için eylem veya eylem dinleyicisi kullanmayın.

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

Fasulye:

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