Bonjour,
J'ai un arbre dans ma page jsp :
Cette arbre est initialisé par une méthode statique contenue dans mon bean. J'ai egalement implémenté un listener dans ce bean pour recuperer le nom de l'element selectionné (voir methode retrieveElement). Mais le probleme, c'est que je n'arrive pas à faire un binding entre mon arbre avec mon instance de HtmlTree dans mon bean...
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 <html> <%@ page import="org.apache.myfaces.custom.tree.model.DefaultTreeModel, com.perso.directory.beans.DatabaseBean"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="html" %> <%@ taglib uri="http://myfaces.apache.org/extensions" prefix="ext"%> <core:view> <head> <title>Vision des tables</title> </head> <body> <% if (pageContext.getAttribute("treeModel", PageContext.SESSION_SCOPE) == null) { pageContext.setAttribute("treeModel", new DefaultTreeModel(DatabaseBean.initTree()), PageContext.SESSION_SCOPE); } %> <table border="1"> <tr> <th> Module </th> <th> Catégorie </th> </tr> <tr> <td> <ext:tree value="#{treeModel}" binding="#{database.tree}"> </ext:tree> </td> <td> </td> </tr> </table> </body> </core:view>![]()
Auriez vous une piste à me donner ?
Voici le code de mon bean :
Merci d'avance
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 package com.perso.directory.beans; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import org.apache.myfaces.custom.tree.DefaultMutableTreeNode; import org.apache.myfaces.custom.tree.HtmlTree; import org.apache.myfaces.custom.tree.event.TreeSelectionEvent; import org.apache.myfaces.custom.tree.event.TreeSelectionListener; import com.perso.directory.DAO.DatabaseHome; public class DatabaseBean { private ArrayList modules; HtmlTree tree; /** * get the list of modules * * @return the list of modules */ public ArrayList getModules() { ... } /** * return the list of items corresponding to the modules * * @return the list of modules */ public Collection getModulesList() { ... } /** * initialize the structure of the database tree in the jsp page * * @return the root node */ public static DefaultMutableTreeNode initTree() { ArrayList modulesTemp = DatabaseHome.getModules(); Iterator iter = modulesTemp.iterator(); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Database"); while (iter.hasNext()) { ModuleBean item = (ModuleBean)iter.next(); DefaultMutableTreeNode node = new DefaultMutableTreeNode(item.getCode()); root.insert(node); } return root; } /** * get the database tree of the jsp page * * @return the HtmlTree */ public HtmlTree getTree() { return tree; } /** * set the database tree of the jsp page * * @param newTree */ public void setTree(HtmlTree newTree) { tree = newTree; } /** * get element in the tree * */ public void retrieveElement(ActionEvent actionEvent) { tree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getSelectionPath().getLastPathComponent(); if (node == null) return; //Object nodeInfo = node.getUserObject(); System.out.println(node.toString()); ///... /* React to the node selection. */ //... } }); } }
@+
Jorus
Partager