Rich:tree remove a node
keyga Dec 16, 2010 4:45 AMHi everyone,
I have a rich:tree which works with a recursiveTreeNodesAdaptor, and my question is how can I remove a selected node?
My recursive bean:
public class Organisation implements Serializable { private static final long serialVersionUID = 1L; private List<Organisation> children; private String type; private Item item; private Organisation parent; ... public void removeChild() { Organisation item = DynamicTree.getChildSelected(); // get the selected node as an Organisation if (item != null){ if(item.getParent() != null){ // if it's not the root node Organisation parent = item.parent; List<Organisation> list_children = parent.getChildren(); int i = 0; for(Organisation o : list_children){ if(organisationAreEquals(o, item)){ // if we found the child to delete break; } i++; } list_children.remove(i); } }
But apparently we can't use "remove", I don't know why, I get this error:
Caused by: java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableList.remove(Collections.java:1162) at prototype.dynamictree.model.Organisation.removeChild(Organisation.java:152) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.el.parser.AstValue.invoke(AstValue.java:191) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) ... 174 more
Here is my xhtml code:
<rich:tree id="dynamicTree" ajaxSubmitSelection="true" ajaxSingle="true" swichType="server" nodeSelectListener="#{dynamicTree.processNodeSelection}" rightClickSelection="true"> <rich:recursiveTreeNodesAdaptor roots="#{rootOrganisation}" id="dynamicRecursiveTree" switchType="server" var="_rootOrganisation"> <rich:treeNode> <h:outputText value="MENU" /> <rich:componentControl disableDefault="true" event="oncontextmenu" for="#{_rootOrganisation.type}ContextMenu" operation="show" /> </rich:treeNode> <rich:recursiveTreeNodesAdaptor roots="#{_rootOrganisation.children}" var="_childOrganisation" nodes="#{_childOrganisation.children}"> <rich:treeNode> <h:outputText value="#{_childOrganisation.item.name}" /> <rich:componentControl disableDefault="true" event="oncontextmenu" for="#{_childOrganisation.type}ContextMenu" operation="show" /> </rich:treeNode> </rich:recursiveTreeNodesAdaptor> </rich:recursiveTreeNodesAdaptor> </rich:tree>
Thank you for your help