I have a Tree primefaces component that i customized in my code, here is the code of this jsf page that contain my treeNodes :
<h:form id="formNode">
<p:commandButton value="+Add" oncomplete="PF('w_addRoot').show();" />
<p:tree value="#{treeManagedBean.root}" var="node" animate="true" dynamic="true"
selection="#{treeManagedBean.selectedNode}" selectionMode="single"
>
<p:treeNode expandedIcon="ui-icon ui-icon-folder-open"
collapsedIcon="ui-icon ui-icon-folder-collapsed">
<h:panelGrid style="margin-top: -9px;" columns="2" >
<h:outputText value="#{node}"/>
<p:commandButton action="#{treeManagedBean.createNodeHere}" icon="iconForkTree" style="margin-top: 5px; margin-left:30px; max-width: 15px; max-height: 15px;">
<f:setPropertyActionListener target="#{treeManagedBean.currNodeName}" value="#{node}" />
</p:commandButton>
</h:panelGrid>
</p:treeNode>
<p:treeNode type="document" icon="ui-icon ui-icon-document">
<h:link value="#{node}"/>
</p:treeNode>
<p:ajax event="select" listener="#{treeManagedBean.onNodeSelect}"></p:ajax>
<p:ajax event="unselect" listener="#{treeManagedBean.onNodeUnSelect}"></p:ajax>
<p:ajax event="expand" listener="#{treeManagedBean.onNodeExpand}"></p:ajax>
<p:ajax event="collapse" listener="#{treeManagedBean.onNodeCollapse}"></p:ajax>
</p:tree>
</h:form>
here is the function from the managedBean that should create the child node :
public void createNodeHere(){
System.out.println("current node Name : "+currNodeName);
// get the current node from the giving name currNodeName
currNodeName="";
}
So i want to create a child treeNode when the user click on the commandButton (with plus icon ) ,and the parent of this child treeNode should be the current node . The problem is that i can't get the current Node ( i get only its name ). so can i get the treeNode object from its name ? if not , there is a way to do that without using event ( select , unselect ... )
Note that using f:ajax tag with event attribut(select ,expand ,collapse ,unselect) i can get the current node ,but its not my goal.