jsf - Add and delete nodes in primefaces treeTable -
i have this:
<p:treetable id="#{treetableid}" value="#{tablebeanroot}" var="element" resizablecolumns="true" selection="#{budgettemplateelementbean.selectednode}" selectionmode="single" widgetvar="#{treetableid}widget"> <f:facet name="header"> </f:facet> <p:column style="width:150px"> ..... </p:column> ..... <f:facet name="footer"> <p:commandbutton value="#{msg.addchildnode}" actionlistener="#{actionbean.addchildnodeaction}" process="@this,#{treetableid}" update="#{treetableid} :growl" /> <p:commandbutton value="#{msg.deletenode}" actionlistener="#{actionbean.deletenodeaction}" process="@this,#{treetableid}" update="#{treetableid} :growl" /> </f:facet> </p:treetable>
how add , delete treenodes in primefaces treetable? can put bean?
thanks
one solution add delete nodes can this:
public boolean removeelemetoftreenode(treenode rootnode, treenode nodetodelete) { if (rootnode.getchildren().remove(nodetodelete)) { return true; } else { (treenode childnode : rootnode.getchildren()) { if (childnode.getchildcount() > 0) { return removeelemetoftreenode(childnode, nodetodelete); } } return false; } } public void addnodeaction(actionevent event) { if (selectednode == null) { // todo: añadir excepcion no seleccionado } random randomgenerator = new random(); treenode pepe = new defaulttreenode(new configuration("new node" + randomgenerator.nextint(100), false, "new node" + randomgenerator.nextint(100), false), selectednode.getparent()); return; } public void addchildnodeaction(actionevent event) { if (selectednode == null) { // todo: añadir excepcion no seleccionado } random randomgenerator = new random(); treenode pepe = new defaulttreenode(new configuration("new node" + randomgenerator.nextint(100), false, "new node" + randomgenerator.nextint(100), false), selectednode); return; }
Comments
Post a Comment