Tree - Events An ajax behavior callback is provided for each event such as expand, collapse, select and unselect.
<h:form id="form">
    <p:growl id="messages" showDetail="true" />
    <p:tree value="#{treeEventsView.root}" var="doc" selectionMode="single" selection="#{treeEventsView.selectedNode}">
        <p:ajax event="expand" update=":form:messages" listener="#{treeEventsView.onNodeExpand}" />
        <p:ajax event="collapse" update=":form:messages" listener="#{treeEventsView.onNodeCollapse}" />
        <p:ajax event="select" update=":form:messages" listener="#{treeEventsView.onNodeSelect}" />
        <p:ajax event="unselect" update=":form:messages" listener="#{treeEventsView.onNodeUnselect}" />

        <p:treeNode expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
            <h:outputText value="#{doc.name}"/>
        </p:treeNode>
        <p:treeNode type="document" icon="ui-icon-document">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>
        <p:treeNode type="picture" icon="ui-icon-image">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>
        <p:treeNode type="mp3" icon="ui-icon-video">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>
    </p:tree>
</h:form> 
                
PrimeTek, Copyright © 2017
All rights reserved.
Running PrimeFaces-6.2-SNAPSHOT on Mojarra-2.3.2.