p:在p:对话框中放置在p:dataTable中时,不会调用commandLink [英] p:commandLink not invoked when placed in p:dataTable in p:dialog

查看:237
本文介绍了p:在p:对话框中放置在p:dataTable中时,不会调用commandLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是原文,我想从数据库
下载不同格式(pdf,jpg,png)的文件,但是我没有成功实现这个
我看到很多话题像这样,但他们的方法不适合我
这里是html:

I use primefaces and I want to download a file with different formats(pdf, jpg, png, ) from database but I don't succed to realise this I have seen a lot of topic like this but their methods don't work for me here is the 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;
}

always,image.getContentType()返回null
和字节。长度不为空

always, image.getContentType() return null and bytes.length not null

你有什么想法

谢谢

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

I just know the problem, I put the download link in dialog box, because when i make a test outside the dialog it works here is the test that it works :

 <h:form>

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

这里是对话框内的测试:

and here is the test inside the dialog :

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

后者不起作用

你有任何想法如何使对话框内的下载链接工作

do you any idea how to make working the download link inside the dialog

提前感谢你

推荐答案

您应该自己设置内容类型。请查看 DefaultStreamedContent的构造函数
所以而不是

You should set the content type yourself. Take a look at the constructors of DefaultStreamedContent. So instead of

StreamedContent image = new DefaultStreamedContent(is);

您应该写

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

确保使用正确的内容类型,以及文件名扩展名。

Make sure you use the proper content type, and extension for filename.

这篇关于p:在p:对话框中放置在p:dataTable中时,不会调用commandLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆