【问题标题】:p:commandLink not invoked when placed in p:dataTable in p:dialog [duplicate]p:commandLink 放置在 p:dialog 中的 p:dataTable 中时未调用 [重复]
【发布时间】:2012-08-08 11:44:01
【问题描述】:

我使用 primefaces,我想从数据库下载不同格式(pdf、jpg、png、)的文件 但我没有意识到这一点 我见过很多这样的话题,但他们的方法对我不起作用 这是html:

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

总是,image.getContentType() 返回 null 并且 bytes.length 不为空

你有什么想法

谢谢


我只是知道问题所在,我将下载链接放在对话框中,因为当我在对话框外进行测试时,它可以工作 这是它的工作测试:

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

后者不起作用

您知道如何在对话框中制作下载链接

提前谢谢你

【问题讨论】:

  • 您没有设置内容类型,因此它为空。可以在DefaultStreamedContent的构造函数中设置内容类型。
  • 我设置了内容类型,在 image.getContentType() 之后返回了我放的值,但是文件没有下载,并且在数据库的表中,文件有超过 20000 kb (我把它保存在mysql中的longblob中),你能发现我的问题吗,谢谢

标签: jsf primefaces datatable dialog commandlink


【解决方案1】:

您应该自己设置内容类型。看看constructors of DefaultStreamedContent。 所以不是

StreamedContent image = new DefaultStreamedContent(is);

你应该写

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

确保使用proper content type 和文件扩展名。

【讨论】:

  • 我写了你正在写的内容,内容类型naw不为空但文件不下载
猜你喜欢
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-31
相关资源
最近更新 更多