I'm trying to add a new node to the tree.I have made a commundButton which is responsible for it.
When I add new node to the nodes which I have created in my java constructor everything is ok, but when I add a node and then I add a node to the one I have created before StuckTrace appears.
This is my xhtml code:
Code: Select all
<h:form>
<p:commandButton value="Add node" update="treeSingle" actionListener="#{treeBean.addNode}" ></p:commandButton>
<p:tree id="treeSingle" value="#{treeBean.root}" var="node"
selectionMode="single"
selection="#{treeBean.selectedNode}">
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
</h:form>
Code: Select all
public TreeBean() {
root = new DefaultTreeNode("Root", null);
TreeNode node0 = new DefaultTreeNode("Node 0", root);
TreeNode node1 = new DefaultTreeNode("Node 1", root);
TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);
}
public void addNode() {
if (selectedNode != null) {
TreeNode node = node=new DefaultTreeNode("New node", selectedNode);
}
}
Code: Select all
WARNING: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.primefaces.component.api.UITree.findTreeNode(UITree.java:112)
at org.primefaces.component.api.UITree.findTreeNode(UITree.java:120)
at org.primefaces.component.api.UITree.setRowKey(UITree.java:79)
at org.primefaces.component.tree.TreeRenderer.decodeSelection(TreeRenderer.java:60)
at org.primefaces.component.tree.TreeRenderer.decode(TreeRenderer.java:36)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at org.primefaces.component.api.UITree.processDecodes(UITree.java:171)
at org.primefaces.component.tree.Tree.processDecodes(Tree.java:343)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:933)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)