IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

[PrimeFaces] Convertir bytes[] en StreamedContent


Sujet :

JSF Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 59
    Points : 41
    Points
    41
    Par défaut [PrimeFaces] Convertir bytes[] en StreamedContent
    bonjour,
    je veux télécharger des fichiers de la base de données a travers le composant de téléchargement de primefaces, alors pour cela j'ai crée une méthode qui converti le fichier du type bytes[] en StreamedContent pour permettre le téléchargement comme il est montrer dans la documentation du composant primefaces
    voila mon code xhtml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <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>
    et voila mon code java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    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;
    }
    byte.length retourne la longueur du fichier mais image.getContentType() retourne null : je sais pas pourquoi,

    quelqu'un saurait il comment résoudre ce problème

    merci d'avance

  2. #2
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 59
    Points : 41
    Points
    41
    Par défaut primeface <p:fileDownload> ne marche pas dans <ui:repeat> et <h:datatable>
    aprés plusieurs tests, j'ai conclut que le composant de telechargement marche bien et la conversion marche bien, mais le probleme c'est lorsque je mets le composant de telechargement <p:fileDownload> dans un <h:datatable> ou bien dans un <ui:repeat> dans ce cas il ne marche pas, et lorsque je le mets en dehors il marche bien
    voila la page xhtml de test :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:c="http://java.sun.com/jsp/jstl/core">
     
        <body>
     
            <ui:composition template="./template_utilisateur.xhtml">
     
                <ui:define name="content">
                    <h:form id="form" >
     
                        <p:dataTable id="cars" var="car" value="#{histCommController.lc}" tableStyle="width:auto">  
     
                            <p:column headerText="Model" style="width:100px">  
                                <h:outputText value="#{car.id}" />  
                            </p:column>  
     
                            <p:column headerText="Year" style="width:100px">  
                                <h:outputText value="#{car.dateEnvoi}" />  
                            </p:column>  
     
                            <p:column headerText="Manufacturer" style="width:100px">  
                                <h:outputText value="#{car.dateLivraisonRecommande}" />  
                            </p:column>  
     
                            <p:column style="width:40px">  
                                <h:panelGrid columns="3" styleClass="actions" cellpadding="2">  
                                    <p:commandButton id="selectButton" update=":form:dlg" oncomplete="dlg.show()" icon="ui-icon-search" title="View">  
                                        <f:setPropertyActionListener value="#{car}" target="#{histCommController.selectedCommande}" />  
                                    </p:commandButton>  
                                </h:panelGrid>  
                            </p:column>  
     
                        </p:dataTable>  
     
                        <p:commandButton oncomplete="dlg.show()" value="lancer le dialog" />
                        <p:dialog id="dlg" widgetVar="dlg" >
     
                            <p:commandLink  id="downloadLink2" value="Download" ajax="false">  
                                <p:fileDownload value="#{histCommController.test}" />  
                            </p:commandLink>
                            <h:dataTable value="#{histCommController.selectedCommande.listFichiers}" var="jjjjj" >
     
                                  <h:column>
                                      <h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" />
                                  </h:column>
                                  <h:column>
                                      <h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" />
                                  </h:column>
                                  <h:column>
                                      <p:commandLink id="downloadLink" value="Download" ajax="false">  
                                                <p:fileDownload value="#{histCommController.test}" />  
                                            </p:commandLink>
                                  </h:column>
     
     
     
                            </h:dataTable>               
                                <ui:repeat value="#{histCommController.selectedCommande.listFichiers}" var="jjjjj">
     
                                            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" />
     
                                            <h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" />
     
                                            <p:commandLink id="downloadLink" value="Download" ajax="false">  
                                                <p:fileDownload value="#{jjjjj.convertFichier}" />  
                                            </p:commandLink>
     
     
                                </ui:repeat>
     
                            <p:commandLink  id="downloadLink" value="Download" ajax="false">  
                                <p:fileDownload value="#{histCommController.test}" />  
                            </p:commandLink>
                        </p:dialog>
     
                    </h:form>
     
     
                </ui:define>
     
            </ui:composition>
     
        </body>
    </html>
    seuls les <p:fileDownload> en dehors de <ui:repeat> et <h:datatable> qui marche

    avez vous déjà rencontrer ce problème, avez vous une idée sur la provenance du problème

    merci bien

Discussions similaires

  1. Convertir Byte en Bitmap
    Par supupoff dans le forum Android
    Réponses: 2
    Dernier message: 20/03/2013, 15h54
  2. [WinRt] Convertir Byte[] en ImageSource
    Par NeoKript dans le forum WinRT
    Réponses: 3
    Dernier message: 08/04/2012, 19h08
  3. Convertir byte[] en float
    Par wedze74 dans le forum C#
    Réponses: 1
    Dernier message: 16/02/2011, 08h50
  4. Convertir BYTE[] vers char *
    Par LordBob dans le forum C++
    Réponses: 4
    Dernier message: 13/10/2007, 10h04
  5. convertir byte[] en InputStreamReader
    Par barthelus76 dans le forum Entrée/Sortie
    Réponses: 2
    Dernier message: 03/10/2007, 13h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo