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 :

JSF RichFaces=> tri de colonnes


Sujet :

JSF Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 49
    Par défaut JSF RichFaces=> tri de colonnes
    Bonjour,
    voila j'ai une DataGrid avec un columnGroup à l'interieur, alimenter par mon bean, et je voudrais qu'en cliquant sur l'intitulé de mes colonnes, les lignes soient triées.

    Ou meme faire aparaitre des petites flèches dans mes entêtes de colonnes pour trier par ordre croissant ou décroissant.

    Je débute en JSF donc allez y molo

  2. #2
    Expert confirmé
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Par défaut
    Bonjour et Bienvenu dans nos forums

    Mauvaise nouvelle: RichFaces n'offre pas le tri automatique des colonnes d'une dataTable. C'est prévu pour la 3.2 je crois.
    Tu devrais le faire à la main, en ajoutant des commandLink dans chaque colonne et en effectuant toi-même le tri.

    Bonne chance.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 49
    Par défaut
    le " scrollableDataTable à la fonction de trie de collonnes integré " mais mon chef trouve l'organisation des donnée moin jolies par contre ....

  4. #4
    Membre éclairé Avatar de danyboy85
    Homme Profil pro
    Développeur Java
    Inscrit en
    Décembre 2005
    Messages
    548
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Décembre 2005
    Messages : 548
    Par défaut
    Citation Envoyé par saubin Voir le message
    le " scrollableDataTable à la fonction de trie de collonnes integré " mais mon chef trouve l'organisation des donnée moin jolies par contre ....
    Et comment fonctionne-elle cette fonction de tri ? Je n'arrive à la mettre en place.

    Une idée ?

  5. #5
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Quel est ton problème au juste ?
    Il me semble (je n'utilise pas ce composant) que c'est automatique, non ?

    De mon côté, j'avais implementé moi même le tri des colonnes sur le rich:datatable (en réalité une datatable à moi, mais qui héritait du rich:datatable)...
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  6. #6
    Membre éclairé Avatar de danyboy85
    Homme Profil pro
    Développeur Java
    Inscrit en
    Décembre 2005
    Messages
    548
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Décembre 2005
    Messages : 548
    Par défaut
    Bah en fait je n'ai rien codé du tout car je ne trouve pas de doc pertinente.

    Mais comme tu dis, apparemment c'est automatique.

    Le problème c'est que quend je clique sur une entête de colonne j'ai l'erreur javascript suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    'startRow' a la valeur Null ou n'est pas un objet
    et celle-ci côté serveur :

    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
     
    22 janv. 2008 15:02:57 com.sun.faces.lifecycle.LifecycleImpl phase
    ATTENTION: executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@c20130) threw exception
    java.lang.IllegalStateException: duplicate Id for a component form_tableau:j_id_jsp_483135046_14
            at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:442)
            at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
            at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
            at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
            at org.ajax4jsf.application.AjaxStateManager.buildSerializedView(AjaxStateManager.java:330)
            at org.ajax4jsf.application.AjaxStateManager.saveSerializedView(AjaxStateManager.java:314)
            at javax.faces.application.StateManager.saveView(StateManager.java:155)
            at com.sun.faces.application.ViewHandlerImpl$WriteBehindStateWriter.flushToWriter(ViewHandlerImpl.java:885)
            at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:183)
            at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
            at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
            at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
            at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            at java.lang.Thread.run(Thread.java:619)
    22 janv. 2008 15:02:57 com.sun.faces.lifecycle.LifecycleImpl phase
    ATTENTION: phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@c20130) threw exception: java.lang.IllegalStateException: duplicate Id for a component form_tableau:j_id_jsp_483135046_14 duplicate Id for a component form_tableau:j_id_jsp_483135046_14
    org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:442)
    org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
    org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
    org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.apply(AjaxStateManager.java:464)
    org.ajax4jsf.application.AjaxStateManager.buildSerializedView(AjaxStateManager.java:330)
    org.ajax4jsf.application.AjaxStateManager.saveSerializedView(AjaxStateManager.java:314)
    org.ajax4jsf.context.AjaxContextImpl.saveViewState(AjaxContextImpl.java:444)
    org.ajax4jsf.event.AjaxPhaseListener.afterPhase(AjaxPhaseListener.java:81)
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    java.lang.Thread.run(Thread.java:619)

  7. #7
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Quel est ton code JSF de ta page ?
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 49
    Par défaut
    Techniquement, la methode de trie est integrée au composant scrollabledatatable mais le probleme c'est qu'en fonction du type de tes donnée ça trie un peut .... à l'arrache.

    J'ai refet mon projet avec iceFaces, un DataTable, et j'ai codé moimeme la fonction de trie, je suppose que tu peux faire la meme chose avec un DataTable avec richFaces =>

    il faut: une classe "mèrer"
    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
     
    public abstract class SortableList {
     
    	protected String sortColumnName;
    	protected boolean ascending;
     
    	// we only want to resort if the oder or column has changed.
    	protected String oldSort;
    	protected boolean oldAscending;
     
    	protected SortableList(String defaultSortColumn) {
    		sortColumnName = defaultSortColumn;
    		ascending = isDefaultAscending(defaultSortColumn);
    		oldSort = sortColumnName;
    		// make sure sortColumnName on first render
    		oldAscending = !ascending;
    	}
     
    	/**
             * Sort the list.
             */
    	protected abstract void sort();
     
    	/**
             * Is the default sortColumnName direction for the given column "ascending" ?
             */
    	protected boolean isDefaultAscending(String sortColumn) {
    		return true;
    	}
     
    	/**
             * Gets the sortColumnName column.
             * 
             * @return column to sortColumnName
             */
    	public String getSortColumnName() {
    		return sortColumnName;
    	}
     
    	/**
             * Sets the sortColumnName column
             * 
             * @param sortColumnName
             *            column to sortColumnName
             */
    	public void setSortColumnName(String sortColumnName) {
    		oldSort = this.sortColumnName;
    		this.sortColumnName = sortColumnName;
     
    	}
     
    	/**
             * Is the sortColumnName ascending.
             * 
             * @return true if the ascending sortColumnName otherwise false.
             */
    	public boolean isAscending() {
    		return ascending;
    	}
     
    	/**
             * Set sortColumnName type.
             * 
             * @param ascending
             *            true for ascending sortColumnName, false for desending
             *            sortColumnName.
             */
    	public void setAscending(boolean ascending) {
    		oldAscending = this.ascending;
    		this.ascending = ascending;
    	}
    }
    et faire hériter ton bean ou tu stock tes données: tonBean extends SortableList

    ajoute la methode Sort() à ton bean ( enfin il faut la redéfinir dans ton bean car elle est déclaré en abstract dans SortableList

    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
     
    protected void sort() {
    		Comparator comparator = new Comparator() {
    			public int compare(Object o1, Object o2) {
    				Abattage c1 = (Abattage) o1;
    				Abattage c2 = (Abattage) o2;
    				if (sortColumnName == null) {
    					return 0;
    				}
    				if (sortColumnName.equals("Numero Officiel")) {
    					return ascending ? c1.getNumOfficiel().compareTo(
    							c2.getNumOfficiel()) : c2.getNumOfficiel()
    							.compareTo(c1.getNumOfficiel());
     
    				}
    				if (sortColumnName.equals("Numero d'ordre")) {
    					return ascending ? new Integer(c1.getNumQualite())
    							.compareTo(new Integer(c2.getNumQualite()))
    							: new Integer(c2.getNumQualite())
    									.compareTo(new Integer(c1.getNumQualite()));
    				}
    				if (sortColumnName.equals("Signe de Qualite")) {
    					return ascending ? c1.getSigneQualite().compareTo(
    							c2.getSigneQualite()) : c2.getSigneQualite()
    							.compareTo(c1.getSigneQualite());
    				}
    				if (sortColumnName.equals("Poids carcasse")) {
    					return ascending ? new Integer(c1.getPoidCarcasse())
    							.compareTo(new Integer(c2.getPoidCarcasse()))
    							: new Integer(c2.getPoidCarcasse())
    									.compareTo(new Integer(c1.getPoidCarcasse()));
    				}
    				if (sortColumnName.equals("Classement Europe")) {
    					return ascending ? c1.getEuropa().compareTo(c2.getEuropa())
    							: c2.getEuropa().compareTo(c1.getEuropa());
    				}
    				if (sortColumnName.equals("Code non qualite")) {
    					return ascending ? c1.getCodeNonQualite().compareTo(
    							c2.getCodeNonQualite()) : c2.getCodeNonQualite()
    							.compareTo(c1.getCodeNonQualite());
    				}
    				if (sortColumnName.equals("Observation")) {
    					return ascending ? c1.getObservation().compareTo(
    							c2.getObservation()) : c2.getObservation()
    							.compareTo(c1.getObservation());
    				}
    				if (sortColumnName.equals("Abattoir")) {
    					return ascending ? c1.getNomAbattoir().compareTo(
    							c2.getNomAbattoir()) : c2.getNomAbattoir()
    							.compareTo(c1.getNomAbattoir());
    				} else
    					return 0;
    			}
    		};
    voila, ensuite dans tas page 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
     
    <ice:dataTable id="dataSortData" 
    			cellspacing="0" 
    			cellpadding="0" 
     
     
    			value="#{TestBean.listeAbbatage}" 
    			var="aba" 
    			sortColumn= "#{TestBean.sortColumnName}"
    			sortAscending= "#{TestBean.ascending}"
    			scrollable = "true"
    			scrollHeight = "270px"			
    			styleClass= "iceDatTbl"
    			rowClasses= "row1,row2"
     
    			columnClasses="tableCol"			
    			columnWidths= "100px,50px,40px,40px,50px,100px,80px,100px">
     
    			<ice:column>
     
    ......etc

  9. #9
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Avec le composant RichFaces (que je n'ai pas utilisé, donc je suppose) l'attribut sortOrder ne permet-il pas de pointer vers sa propre méthode de tri ?
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    49
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 49
    Par défaut
    Si si, je l'ai utilisé, mais comme je l'ai dis dans le mess précedant ça fesait un peut nimp, sur mes 8 colonne il n'en triait que deux, et que dans un seul sens

  11. #11
    Membre éclairé Avatar de danyboy85
    Homme Profil pro
    Développeur Java
    Inscrit en
    Décembre 2005
    Messages
    548
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Décembre 2005
    Messages : 548
    Par défaut
    J'ai en fait décidé de revenir à la libriaire que j'utilsais avant : RCFaces.

    Pour info, cette libriaire offre des composants vraiment sympas et en particulier le dataGrid. Cette librairie est encore en bêta et peu donc comporter quelques bugs mais les développeurs du projet sont très réactifs à la remontée de bugs.


    Site

    Download

Discussions similaires

  1. Tri par colonne de n'importe quel StringGrid
    Par Dionyzos dans le forum Composants VCL
    Réponses: 3
    Dernier message: 02/07/2008, 16h47
  2. Tri des colonnes au choix
    Par nora_ora dans le forum Oracle
    Réponses: 4
    Dernier message: 06/10/2005, 17h11
  3. pb avec tri de colonne via un KStringGrid
    Par steph_1 dans le forum Composants VCL
    Réponses: 5
    Dernier message: 04/10/2005, 11h40
  4. [JTable] Tri des colonnes
    Par djskyz dans le forum Composants
    Réponses: 10
    Dernier message: 17/03/2005, 10h14
  5. Tri des colonnes d'une DBGRID
    Par Atrebate62 dans le forum Bases de données
    Réponses: 3
    Dernier message: 31/05/2004, 12h20

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