2012-08-11 75 views
0

我使用primefaces,我想從數據庫 下載不同格式的文件(pdf,jpg,png),但我沒有成功實現這 我已經看到了很多的話題像這樣但他們的方法不適合我 在這裏工作是HTML:p:在p:data對話框中放置p:dataTable時不會調用commandLink

<ui:repeat value="#{histCommController.selectedCommande.listFichiers}" var="jjjjj"> 
          <tr> 
           <td> 
            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" /> 
           </td> 
           <td> 
            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" /> 
           </td> 
           <td> 
            <p:commandButton id="downloadLink" value="Download" ajax="false" 
                icon="ui-icon-arrowthichk-s"> 
             <p:fileDownload value="#{jjjjj.convertFichieru}" /> 
            </p:commandButton> 
           </td> 
          </tr> 



         </ui:repeat> 

這裏是java:

public StreamedContent convertFichier(byte[] bytes) { 
    InputStream is = new ByteArrayInputStream(bytes); 
    System.out.println("size file : "+bytes.length); 
    StreamedContent image = new DefaultStreamedContent(is); 
    System.out.println("dans le convertisseur : "+image.getContentType()); 
    return image; 
} 

始終,形象。 getContentType()返回null 和字節。長度不爲空

你有什麼想法

謝謝


我只知道這個問題,我把下載鏈接對話框中,因爲當我進行測試的對話外它的工作原理 這裏是它的工作原理測試:

<h:form> 

      <p:commandLink id="downloadLink" value="Download" ajax="false"> 
       <p:fileDownload value="#{histCommController.test}" /> 
      </p:commandLink> 
      </h:form> 

,這裏是在對話框內的檢查:

<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" id="carDlg" 
          showEffect="fade" hideEffect="explode" modal="true"> 

        <table id="gradient-style" > 
         <tr style="border: hidden;"> 
          <th> 
           <h:outputLabel value="Model:" /> 
          </th> 
          <td> 
           <h:outputLabel style="font-weight: bold;" value="#{histCommController.selectedCommande.id}" /> 
          </td>          
         </tr> 
         <tr style="border: hidden;"> 
          <th> 
           <h:outputLabel value="Year:" /> 
          </th> 
          <td> 
           <h:outputLabel style="font-weight: bold;" value="#{histCommController.selectedCommande.etat}" /> 
          </td>          
         </tr> 
         <tr style="border: hidden;"> 
          <th> 
           <h:outputLabel value="Manufacturer:" /> 
          </th> 
          <td> 
           <h:outputLabel style="font-weight: bold;" value="#{histCommController.selectedCommande.dateEnvoi}" /> 
          </td>          
         </tr> 
         <tr style="border: hidden;"> 
          <th> 

           <h:outputLabel value="Color:" /> 
          </th> 
          <td> 
           <h:outputLabel style="font-weight: bold;" value="#{histCommController.selectedCommande.dateLivraisonRecommande}" /> 
          </td>          
         </tr> 
        </table> 
        <table id="gradient-style" > 
         <th>Nom Fichier</th><th>Taille</th><th>Télécharger</th> 
         <ui:repeat value="#{histCommController.selectedCommande.listFichiers}" var="jjjjj"> 
          <tr> 
           <td> 
            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" /> 
           </td> 
           <td> 
            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" /> 
           </td> 
           <td> 
            <p:commandLink id="downloadLink" value="Download" ajax="false"> 
             <p:fileDownload value="#{histCommController.test}" /> 
            </p:commandLink> 
           </td> 
          </tr> 



         </ui:repeat> 

        </table> 


       </p:dialog> 

後者不起作用

對你有任何想法如何使工作的對話框

內的下載鏈接預先感謝您

+0

您沒有設置內容類型,因此它是空的。您可以在'DefaultStreamedContent'的構造函數中設置內容類型。 – siebz0r 2012-08-11 13:19:33

+0

我設置的內容類型和image.getContentType()返回的值,我把,但文件不下載,並在數據庫中的表中,該文件有超過20000 kb(我將它保存在longblob中mysql),你能檢測到我的問題,謝謝 – begiPass 2012-08-12 09:47:36

回答

0

你應該設置內容類型自己。看看constructors of DefaultStreamedContent。 所以不是

StreamedContent image = new DefaultStreamedContent(is); 

你應該寫

StreamedContent image = new DefaultStreamedContent(is, "image/jpeg", "fileName.jpg"); 

確保您使用的proper content type,並擴展文件名。

+0

我寫了你正在寫什麼,內容類型naw不是null,但文件不下載 – begiPass 2012-08-12 09:51:56

相關問題