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 :

Icon TreeView dynamique


Sujet :

JSF Java

  1. #1
    Membre averti
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mai 2010
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mai 2010
    Messages : 26
    Par défaut Icon TreeView dynamique
    Bonjour,

    J'ai implémenté la treeView de la bibliothèque Richfaces en se basant sur 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
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    package org.richfaces.demo.tree;
     
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
     
    import javax.faces.FacesException;
    import javax.faces.component.UIComponent;
    import javax.faces.context.ExternalContext;
    import javax.faces.context.FacesContext;
     
    import org.richfaces.component.UITree;
    import org.richfaces.component.html.HtmlTree;
    import org.richfaces.event.NodeSelectedEvent;
    import org.richfaces.model.TreeNode;
    import org.richfaces.model.TreeNodeImpl;
     
    public class SimpleTreeBean {
     
        private TreeNode rootNode = null;
        private List<String> selectedNodeChildren = new ArrayList<String>();    
     
        private String nodeTitle;
        private static final String DATA_PATH = "/richfaces/tree/examples/simple-tree-data.properties";
     
        private void addNodes(String path, TreeNode node, Properties properties) {
            boolean end = false;
            int counter = 1;
     
            while (!end) {
                String key = path != null ? path + '.' + counter : String.valueOf(counter);
     
                String value = properties.getProperty(key);
                if (value != null) {
                    TreeNodeImpl nodeImpl = new TreeNodeImpl();
                    nodeImpl.setData(value);
                    node.addChild(new Integer(counter), nodeImpl);
                    addNodes(key, nodeImpl, properties);
                    counter++;
                } else {
                    end = true;
                }
            }
        }
     
        private void loadTree() {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);
            try {
                Properties properties = new Properties();
                properties.load(dataStream);
     
                rootNode = new TreeNodeImpl();
                addNodes(null, rootNode, properties);
     
            } catch (IOException e) {
                throw new FacesException(e.getMessage(), e);
            } finally {
                if (dataStream != null) {
                    try {
                        dataStream.close();
                    } catch (IOException e) {
                        externalContext.log(e.getMessage(), e);
                    }
                }
            }
        }
     
        public void processSelection(NodeSelectedEvent event) {
            HtmlTree tree = (HtmlTree) event.getComponent();
            nodeTitle = (String) tree.getRowData();
            selectedNodeChildren.clear();
            TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
            if (currentNode.isLeaf()){
                selectedNodeChildren.add((String)currentNode.getData());
            }else
            {
                Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
                while (it!=null &&it.hasNext()) {
                    Map.Entry<Object, TreeNode> entry = it.next();
                    selectedNodeChildren.add(entry.getValue().getData().toString()); 
                }
            }
        }
     
        public TreeNode getTreeNode() {
            if (rootNode == null) {
                loadTree();
            }
     
            return rootNode;
        }
     
     
     
        public String getNodeTitle() {
            return nodeTitle;
        }
     
        public void setNodeTitle(String nodeTitle) {
            this.nodeTitle = nodeTitle;
        }
     
     
    }
    Le code dans la page xhtml est:
    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
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">
     
        <style>
            .col, .col2 {
                width:50%;
                vertical-align:top;
            }
        </style>
     
     
        <h:form>    
            <h:panelGrid columns="2" width="100%" columnClasses="col1,col2">
     
                <rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}" 
                    reRender="selectedNode" ajaxSubmitSelection="true"  switchType="client"
                    value="#{simpleTreeBean.treeNode}" var="item" ajaxKeys="#{null}">
                </rich:tree>
     
                <h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />
     
            </h:panelGrid>
     
        </h:form>
     
    </ui:composition>
    Le problème est que je veux que pour chaque noeud aura une icon personnalisée affecté dynamiquement.
    Pour le paramètre local nodeImpl de type org.richfaces.model.TreeNode n'a pas les propriétés icon,iconLeaf,....
    Par contre le type org.richfaces.component.html.HtmlTreeNode a ces propriétés.

    Est ce que quelqu'un a une idée sur ce problème???

  2. #2
    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
    Bonjour,

    Pourrais-tu préciser la version de RF que tu utilises ?
    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

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mai 2010
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mai 2010
    Messages : 26
    Par défaut
    La version utilisée est la 3.3.3!!!!!

Discussions similaires

  1. remplissage treeview dynamique
    Par bingo00 dans le forum C#
    Réponses: 4
    Dernier message: 20/05/2007, 23h13
  2. [Struts-Layout] Treeview Dynamique
    Par lili2704 dans le forum Struts 1
    Réponses: 7
    Dernier message: 17/04/2007, 17h19
  3. [Struts-Layout] Treeview Dynamique
    Par JerBi dans le forum Struts 1
    Réponses: 3
    Dernier message: 05/04/2007, 13h31
  4. Réponses: 2
    Dernier message: 27/09/2006, 14h22
  5. TreeView dynamique
    Par partyboy dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 16/05/2006, 11h41

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