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 :

tableaux imbriqués avec Richfaces


Sujet :

JSF Java

  1. #1
    Membre habitué

    Profil pro
    Inscrit en
    Février 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Février 2009
    Messages : 49
    Points : 174
    Points
    174
    Par défaut tableaux imbriqués avec Richfaces
    Bonjour ,
    j'essaie de faire un tableau scrollable composé de 4 colonnes le 1ér colonne contient les services le 2éme contient les demandes associées à ce service et le 3éme les réponses de ce même service .
    j'ai essayé de faire des tables imbriquées en insérant une datatable dans le 2éme colonne mais en affichage je n'obtient que le header de datatable et non pas toute la liste .
    est ce que quelqu'un peut m'aider ou me proposer un petit bout de code.


    voilà mon code :
    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
     
    <rich:panel id="panel_list_lettresorateur" >
                    <f:facet name="header">
                        <h:outputText value="Liste des Collaborateurs "/>
                    </f:facet>
                    <rich:scrollableDataTable   width="100%" height="1000px" rowKeyVar="rkv" frozenColCount="1" 
                                                id="lettresList" value="#{LettresBean.list_prestations}" var="lettres" sortMode="single" 
                                                binding="#{LettresBean.lettreTable}" rowClasses="panel_2">
     
                        <rich:column  id="presta_lib" width="300px"> 
                            <f:facet name="header">
                                <h:outputText styleClass="headerText" value="Prestation" />
                            </f:facet>
                            <h:outputText  value="#{lettres.prestNom}" />
                        </rich:column>
                        <rich:column  id="demande_list"  width="100px" > 
                            <f:facet name="header" >
                                <h:outputText styleClass="headerText" value="Demandes"/>
                            </f:facet>
                            <rich:dataTable value="#{CollabBean.collabs}" var="collab" width="80px">
                                <rich:column id="collNom" >
                                    <f:facet name="header">
                                        <h:outputText styleClass="titre2" value="Collab" />
                                    </f:facet>
                                    <h:outputText  styleClass="titre2" value="#{collab.collNom}" />
                                </rich:column>
                            </rich:dataTable>
                        </rich:column>
                        <rich:column  id="reponse_list" width="100px"> 
                            <f:facet name="header">
                                <h:outputText styleClass="headerText" value="Reponses"/>
                            </f:facet>
                        </rich:column>
                        <rich:column id="printPDF" width="25px"> 
                            <h:graphicImage value="/images/Icone_pdf.png" style="cursor:pointer" />
     
                        </rich:column>
                        <rich:column id="PrintWord" width="25px"> 
                            <h:graphicImage value="/images/icone-word.gif" style="cursor:pointer"/>
                        </rich:column>
                    </rich:scrollableDataTable>
                </rich:panel>

  2. #2
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    C'es possible avec dataTable,
    tu peux également utiliser subTable, un exemple est donnée dans la démo de RichFaces.

  3. #3
    Membre habitué

    Profil pro
    Inscrit en
    Février 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Février 2009
    Messages : 49
    Points : 174
    Points
    174
    Par défaut presque résolu
    avec datatables imbriqués l'affichage est bon
    mais il me reste comment alimenter les listes pour remplir les colonnes

  4. #4
    Expert confirmé
    Avatar de X-plode
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2005
    Messages
    682
    Détails du profil
    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2005
    Messages : 682
    Points : 4 883
    Points
    4 883
    Par défaut
    Bonsoir,

    Je ne sais pas si c'est exactement se que tu veux mais avec Datatable tu peux faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <h:dataTable  border="1" width="885" cellspacing="1" rules="all" value="#{developpez.listToDataModel}" var="dvp"  >
          <h:column>
           <f:facet name="header">
            <h:outputText value="Réf" />
           </f:facet>
           <h:outputText value="#{dvp.idDeveloppez}" />
          </h:column>
           <h:column>

  5. #5
    Membre habitué

    Profil pro
    Inscrit en
    Février 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Février 2009
    Messages : 49
    Points : 174
    Points
    174
    Par défaut plus de détails
    mon nouveau code richfaces est le suivant :
    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
     
         <rich:panel id="panel_list_lettres" >
                    <f:facet name="header">
                        <h:outputText value="Liste des Lettres à éditer "/>
                    </f:facet>
                    <rich:dataTable   width="580px" rowKeyVar="rkv"
                                      id="lettresList" value="#{PrestaBean.prestas}" var="Prestas" sortMode="single" 
                                      rowClasses="panel_2" columnClasses="titre2">
     
                        <rich:column  id="presta_lib" width="300px" > 
                            <f:facet name="header">
                                <h:outputText styleClass="headerText" value="Prestation" />
                            </f:facet>
                            <h:outputText  value="#{Prestas.prestNom}" />
                        </rich:column>
                        <rich:column  id="demande_list"  width="100px" > 
                            <f:facet name="header" >
                                <h:outputText styleClass="headerText" value="Demandes"/>
                            </f:facet>
                            <rich:dataTable value="#{LettresBean.allprestaattributes}" var="demandes" width="80px">
                                <rich:column id="collNom" >
                                    <h:outputText  styleClass="titre2" value="#{demandes.id.demLibelle}" />
                                </rich:column>
                                <rich:column id="printPDF" width="25px"> 
                                    <h:graphicImage value="/images/Icone_pdf.png" style="cursor:pointer" />
                                </rich:column>
                                <rich:column id="PrintWord" width="25px"> 
                                    <h:graphicImage value="/images/icone-word.gif" style="cursor:pointer"/>
                                </rich:column>
                            </rich:dataTable>
                        </rich:column>
                        <rich:column  id="reponse_list" width="100px"> 
                            <f:facet name="header">
                                <h:outputText styleClass="headerText" value="Reponses"/>
                            </f:facet>
                            <rich:dataTable value="#{LettresBean.list_reponses}" var="reponses" width="80px">
                                <rich:column id="collNom" >
                                    <h:outputText  styleClass="titre2" value="#{reponses.id.repLibelle}" />
                                </rich:column>
                                <rich:column id="printPDF" width="25px"> 
                                    <h:graphicImage value="/images/Icone_pdf.png" style="cursor:pointer" />
                                </rich:column>
                                <rich:column id="PrintWord" width="25px"> 
                                    <h:graphicImage value="/images/icone-word.gif" style="cursor:pointer"/>
                                </rich:column>
                            </rich:dataTable>
                        </rich:column>
     
                    </rich:dataTable>
                </rich:panel>
    la liste des prestations esx extraite à partir de ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    public List findAllPresattion() {
     
            return this.getHibernateTemplate().find("from Prestation");
        }
    la liste des réponses à partir de cette méthode :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    public List findAllReponses() {
            return this.getHibernateTemplate().find("from Reponse R where R.id.repPrest=2");
        }
    NB : je vais modifier cette méthode c seulement pour le test.


    la liste des demandes est extraite à pertir de cette méthode :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public List getAllprestaattributes() {
            this.getList_prestations();
            list_demandes.clear();
            for (Iterator it = list_prestations.iterator(); it.hasNext();) {
                Prestation presta = (Prestation) it.next();
                List interm = new ArrayList(presta.getDemandes());
                list_demandes.add(interm);
            }
     
            return list_demandes;
        }

    quand je fais appel à cette méthode une exception se lance au niveau de :

    List interm = new ArrayList(presta.getDemandes());
    l'exception est : org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Juris.hbm.Prestation.demandes, no session or session was closed
    pour plus de détails voici les fichiers HBM associé à ces 3 classes :
    classe prestations :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
      <class lazy="false" name="Juris.hbm.Prestation" table="prestation">
        <id name="prestCode" type="short">
          <column name="prest_code"/>
          <generator class="assigned"/>
        </id>
        <property name="prestNom" type="string">
          <column length="50" name="prest_nom" not-null="true"/>
        </property>
        <property name="prestDia" type="short">
          <column name="prest_dia"/>
        </property>
        <property name="prestPc" type="short">
          <column name="prest_pc"/>
        </property>
        <set inverse="true" name="prestacommunes">
          <key>
            <column name="prest_code" not-null="true"/>
          </key>
          <one-to-many class="Juris.hbm.Prestacommune"/>
        </set>
        <set inverse="true" name="lettreCmds">
          <key>
            <column name="prest_code" not-null="true"/>
          </key>
          <one-to-many class="Juris.hbm.LettreCmd"/>
        </set>
        <set inverse="true" name="tarifs">
          <key>
            <column name="prest_code" not-null="true"/>
          </key>
          <one-to-many class="Juris.hbm.Tarif"/>
        </set>
        <set inverse="true" name="demandes"  >
          <key>
            <column name="dem_presta" not-null="true"/>
          </key>
          <one-to-many class="Juris.hbm.Demande" />
        </set>
        <set inverse="true" name="reponses">
          <key>
            <column name="rep_prest" not-null="true"/>
          </key>
          <one-to-many class="Juris.hbm.Reponse"/>
        </set>
      </class>
    </hibernate-mapping>
    classe Demande :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
      <class lazy="true" name="Juris.hbm.Demande" table="demande">
        <composite-id class="Juris.hbm.DemandeId" name="id">
          <key-property name="demPresta" type="short">
            <column name="dem_presta"/>
          </key-property>
          <key-property name="demLibelle" type="string">
            <column length="60" name="dem_libelle"/>
          </key-property>
          <key-property name="demXml" type="string">
            <column length="30" name="dem_xml"/>
          </key-property>
          <key-property name="demDestinataire" type="string">
            <column length="30" name="dem_destinataire"/>
          </key-property>
        </composite-id>
        <many-to-one class="Juris.hbm.Prestation" fetch="select" insert="false" name="prestation" update="false">
          <column name="dem_presta" not-null="true"/>
        </many-to-one>
      </class>
    </hibernate-mapping>
    classe Reponses :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
      <class lazy="false" name="Juris.hbm.Reponse" table="reponse">
        <composite-id class="Juris.hbm.ReponseId" name="id">
          <key-property name="repPrest" type="short">
            <column name="rep_prest"/>
          </key-property>
          <key-property name="repLibelle" type="string">
            <column length="60" name="rep_libelle"/>
          </key-property>
          <key-property name="repXml" type="string">
            <column length="30" name="rep_xml"/>
          </key-property>
        </composite-id>
        <many-to-one class="Juris.hbm.Prestation" fetch="select" insert="false" name="prestation" update="false">
          <column name="rep_prest" not-null="true"/>
        </many-to-one>
      </class>
    </hibernate-mapping>
    merci d'avance

  6. #6
    Membre habitué

    Profil pro
    Inscrit en
    Février 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Février 2009
    Messages : 49
    Points : 174
    Points
    174
    Par défaut
    finalement j'ai trouvé une solution :
    1) j'ai crée une classe qui implémente java.io.Serializable et qui contient les types des valeurs que je vais integrer dans ma table
    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
     
    public class ListeLettres implements java.io.Serializable {
     
        private String prestaName;
        private List list_demandes;
        private List list_reponse;
     
        public ListeLettres() {
        }
     
        public ListeLettres(String firstName, List list_demandes, List list_reponse) {
            this.prestaName = firstName;
            this.list_demandes = list_demandes;
            this.list_reponse = list_reponse;
        }
    //getters and setters
    .......................
    2) j'ai crée uneJSF ManagedBean qui va remplir un dataModel qui sera la source pour alimenter ma datatable
    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
     
    import Juris.hbm.Prestation;
    import Juris.hbm.Reponse;
    import Juris.hbm.ListeLettres;
    import Juris.service.LettreService;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import javax.faces.model.DataModel;
    import javax.faces.model.ListDataModel;
     
    /**
     *
     * @author TOSHIBA A100
     */
    public class DataTableManager extends ManagedBean{
     
        private LettreService lettreService;
        // Returns sample data
        public DataModel getSampleModel() {
            List<ListeLettres> lettres = new ArrayList<ListeLettres>();
            List list_prestations = lettreService.findAllPresattion();
            for (Iterator it = list_prestations.iterator(); it.hasNext();) {
                Prestation presta = (Prestation) list_prestations.get(list_prestations.indexOf(it.next()));
                List list_reponses = lettreService.findAllReponses(presta.getPrestCode());
                List l = new ArrayList();
                for (Iterator its = list_reponses.iterator(); its.hasNext();) {
                    Reponse rep = (Reponse) list_reponses.get(list_reponses.indexOf(its.next()));
                    l.add(rep.getId().getRepLibelle());
                }
                List list_demandes = lettreService.findAllDemandes(presta.getPrestCode());
                lettres.add(new ListeLettres(presta.getPrestNom(), list_demandes, l));
            }
            return (new ListDataModel(lettres));
        }
     
        public DataTableManager() {
        }
     
        public LettreService getLettreService() {
            return lettreService;
        }
     
        public void setLettreService(LettreService lettreService) {
            this.lettreService = lettreService;
        }
    }
    3) le code JSF :
    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
     
    <%-- 
        Document   : testdatatable
        Created on : 12 avr. 2009, 23:23:03
        Author     : TOSHIBA A100
     
    --%>
     
    <%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
    <%@taglib uri="http://richfaces.org/rich" prefix="rich"%>
     
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
     
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
     
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <f:view>
                <a4j:loadStyle src="#{DataTableManager.path}"/>
                <a4j:loadScript src="#{DataTableManager.scriptpath}"/>
     
                <rich:dataTable rowClasses="panel_2" columnClasses="titre2" value="#{DataTableManager.sampleModel}" var="lettres">
                    <f:facet name="header">
                        <h:outputText value="Listes des lettres pour cette Commande " />
                    </f:facet>
                    <rich:column >
                        <f:facet name="header">
                            <h:outputText value="Prestations : " />
                        </f:facet>
                        <h:outputText value="#{lettres.prestaName}" />
                    </rich:column>
                    <rich:column >
                        <f:facet name="header">
                            <h:outputText value="Demandes : " />
                        </f:facet>
                        <rich:dataTable value="#{lettres.list_demandes}" var="demandes">
                            <rich:column width="200px">
                                <h:outputText value="#{demandes}" />
                            </rich:column>
                            <rich:column id="printPDF" width="25px"> 
                                <h:graphicImage value="/images/Icone_pdf.png" style="cursor:pointer" />
                            </rich:column>
                            <rich:column id="PrintWord" width="25px"> 
                                <h:graphicImage value="/images/icone-word.gif" style="cursor:pointer"/>
                            </rich:column>
                        </rich:dataTable>
     
                    </rich:column>
                    <rich:column >
                        <f:facet name="header">
                            <h:outputText value="Reponses : " />
                        </f:facet>
                        <rich:dataTable value="#{lettres.list_reponse}" var="reponses">
                            <rich:column width="200px">
                                <h:outputText value="#{reponses}" />
                            </rich:column>
                            <rich:column id="printPDF" width="25px"> 
                                <h:graphicImage value="/images/Icone_pdf.png" style="cursor:pointer" />
                            </rich:column>
                            <rich:column id="PrintWord" width="25px"> 
                                <h:graphicImage value="/images/icone-word.gif" style="cursor:pointer"/>
                            </rich:column>
                        </rich:dataTable>
                    </rich:column>
                </rich:dataTable>
            </f:view>
        </body>
    </html>
    4) voici le résultat :

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Treeview avec des tableaux imbriqués
    Par pontus21 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 27/04/2009, 17h06
  2. Réponses: 0
    Dernier message: 12/02/2009, 13h07
  3. OnClick avec Tableaux imbriqués
    Par bondak dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 02/08/2007, 20h19
  4. Recupération de tableaux PHP avec PL/pgSQL
    Par moog dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 25/02/2005, 17h11
  5. Requete select imbriqués avec plusieurs références
    Par GAlion dans le forum Langage SQL
    Réponses: 4
    Dernier message: 06/08/2004, 14h06

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