[RichFaces / Tree] Méthode selectionChanged jamais appelée
Bonjour,
J'ai créé une arborescence grâce à la balise tree du framework RichFaces.
Mon problème est que lors de la sélection d'un noeud (même de plusieurs à la suite) ma méthode selectionChanged n'est jamais appelée.
Voici le code :
view.xhtml
Code:
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
|
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:roa="http://richfaces.org/a4j"
xmlns:ror="http://richfaces.org/rich"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<h:outputStylesheet name="css/jsfcrud.css"/>
<ui:composition template="/templates/default.xhtml">
<ui:define name="title">#{UserI_RB.DossiersTitle}</ui:define>
<ui:define name="body">
<roa:outputPanel ajaxRendered="true">
<ror:messages
globalOnly="true"
styleClass="errors" />
</roa:outputPanel>
<ror:tree
var="item"
treeSelectionChangeListener="#{fileSystemController.selectionChanged}"
rowKeyVar="key">
<ror:treeModelRecursiveAdaptor
roots="#{fileSystemController.roots}"
nodes="#{item.directories}">
<ror:treeNode>
#{item.shortPath}
</ror:treeNode>
<ror:treeModelAdaptor nodes="#{item.files}">
<ror:treeNode>
#{item.shortPath}
</ror:treeNode>
</ror:treeModelAdaptor>
</ror:treeModelRecursiveAdaptor>
</ror:tree>
</ui:define>
</ui:composition>
</h:body>
</html> |
FileSystemController.java
Code:
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
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.klme.war.files.beans;
import com.klme.ejb.exceptions.EJBKException;
import com.klme.war.beans.util.Global;
import com.klme.war.beans.util.JsfUtil;
import com.klme.war.bundles.util.Bundle;
import com.klme.war.files.FileSystemNode;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.AbortProcessingException;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.event.TreeSelectionChangeListener;
import org.richfaces.event.TreeToggleEvent;
/**
*
* @author davd
*/
@ManagedBean(name = "fileSystemController")
@RequestScoped
public class FileSystemController {
private final String rootPath = Global.FILES_PATH;
private List<FileSystemNode> roots;
private FileSystemNode selection;
public void toggleListener(TreeToggleEvent event) {
}
public synchronized List<FileSystemNode> getRoots() {
ResourceBundle err_rb = Bundle.Err.getBundle();
if (roots == null) {
try {
FileSystemNode fsn = new FileSystemNode(rootPath);
roots = fsn.getDirectories();
} catch (EJBKException ex) {
roots = new ArrayList<FileSystemNode>();
JsfUtil.addErrorMessage(err_rb.getString("noResultException_file"));
Logger.getLogger(FileSystemController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return roots;
}
/** Creates a new instance of FileSystemController */
public FileSystemController() {
}
public void selectionChanged(TreeSelectionChangeEvent tsce) {
System.out.println("test");
}
} |
FileSystemNode.java
Code:
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.klme.war.files;
import com.klme.ejb.entities.Fichier;
import com.klme.ejb.exceptions.EJBKException;
import com.klme.ejb.sessionbeans.FichierFacadeLocal;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.EJB;
import org.richfaces.model.TreeNode;
/**
*
* @author davd
*/
public class FileSystemNode implements TreeNode {
private final String path;
private String shortPath;
private FileSystemNode parent;
private Map<String, FileSystemNode> childs;
private Fichier details;
@EJB
private FichierFacadeLocal ejbFacade;
public synchronized String getShortPath() {
if (shortPath == null) {
String[] tmp = path.split("/");
shortPath = tmp[tmp.length-1];
}
return shortPath;
}
public synchronized List<FileSystemNode> getDirectories() throws EJBKException {
List<FileSystemNode> directories = new ArrayList<FileSystemNode>();
Collection<FileSystemNode> coll = childs.values();
for(Iterator<FileSystemNode> it = coll.iterator(); it.hasNext();) {
FileSystemNode child = it.next();
if (!child.isLeaf()) {
directories.add(child);
}
}
return directories;
}
public synchronized List<FileSystemNode> getFiles() {
List<FileSystemNode> files = new ArrayList<FileSystemNode>();
File file = new File(path);
if (file.isDirectory()) {
for (File f : file.listFiles()) {
if (!f.isDirectory()) {
files.add(new FileSystemNode(f.getName()));
}
}
}
return files;
}
public FileSystemNode(String path) {
this.path = path;
childs = new HashMap<String, FileSystemNode>();
File file = new File(path);
if (file.isDirectory()) {
for (File f : file.listFiles()) {
FileSystemNode fsn = new FileSystemNode(f.getAbsolutePath());
//fsn.details = ejbFacade.sOneChemin(f.getAbsolutePath());
childs.put(fsn.path, fsn);
}
}
}
@Override
public TreeNode getChild(Object o) {
return childs.get(indexOf(o));
}
@Override
public int indexOf(Object o) {
return 0;
}
@Override
public Iterator<Object> getChildrenKeysIterator() {
List<Object> keys = new ArrayList<Object>();
Set<String> childKeys = childs.keySet();
for (Iterator<String> childKIt = childKeys.iterator(); childKIt.hasNext();) {
String key = childKIt.next();
keys.add(key);
}
return keys.iterator();
}
@Override
public boolean isLeaf() {
return childs.isEmpty();
}
@Override
public void addChild(Object o, TreeNode tn) {
childs.put((String) o, (FileSystemNode) tn);
}
@Override
public void insertChild(int i, Object o, TreeNode tn) {
childs.put((String) o, (FileSystemNode) tn);
}
@Override
public void removeChild(Object o) {
childs.remove(o);
}
} |
Quelqu'un saurait-il m'expliquer comment procéder ?
Merci d'avance pour votre aide.