have you try to call the nodeStructureChanged from the TreeModel Le 17 nov. 04, � 16:34, Borja Mart�n a �crit :
yes I did, either by giving the parent node, the new node and the root node as parameter.
when the node where I'm inserting the new node is not a leaf node, I still become that exception(but the new node is correctly inserted)
bye
hi, I was testing the tree component and would like to know which is the correct way to add and remove nodes from the tree. Using a TreeSelectionListener implementation I'm able to get the selected node and to add and remove nodes but with a curious behaviour:--
- If I try to add a new node in another node that has already children, I become this exception: "javax.faces.FacesException: Index: 1, Size: 1" but if a refresh the page without submitting the post request again, I can see that the node was correctly inserted
- If I add a new node inside a leaf node, it is inserted correctly
-If I remove a node, it's removed correctly, but then if I select another node, I become this exception: "javax.faces.FacesException: Index: 1, Size: 1" , but if I do as before and refresh the page without sending the post request, the node is still remove and I can continue selecting other nodes
this is the code I'm using to achieve that:
� the selection listener:
public class TreeSelectionListener
implements net.sourceforge.myfaces.custom.tree.event.TreeSelectionListener
{
public void valueChanged(TreeSelectionEvent event)
{
HtmlTree tree = (HtmlTree) event.getSource();
TreePath selection = tree.getSelectionPath();
if (selection != null)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)selection.getLastPathComponent();
getTreeForm().setSelectedNode(node);
}
}
private TreeForm getTreeForm() { Object obj = FacesContext.getCurrentInstance().getApplication() .getVariableResolver().resolveVariable( FacesContext.getCurrentInstance(), "treeForm"); return (TreeForm)obj; }
}
�the adding and removing method from TreeForm
public void setSelectedNode(DefaultMutableTreeNode node) { _selectedNode = node; }
public String addNode() { if (_selectedNode == null) return "ok";
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(_nodeLabel);
_selectedNode.insert(newNode);
_nodeLabel = "";
return "ok"; }
public String delete() { if (_selectedNode == null) return "ok";
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)_selectedNode.getParent();
//if the selected node isnt the root node if (parent != null) { int pos = parent.getIndex(_selectedNode); parent.remove(pos); _selectedNode = parent; }
return "ok"; }
any suggestion?
thanks in advance
Nicolas Arni-Bloch
Groupe MATIS-Bd, Centre Universitaire d'Informatique
24 rue General-Dufour
CH-1205 Gen�ve
eMail : [EMAIL PROTECTED]
phone : +41 22 379 76 80
fax : +41 22 379 77 80
</blockquote></x-html>

