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