There have been a couple of posting asking about Tree2 Lazy Loading.
This is a snippet of what we've done:

<t:tree2 id="serverTree" value="#{myTreeBackerBean.treeData}" var="node"
varNodeToggler="t" clientSideToggle="false" showNav="false">
        <f:facet name="module">
                <h:panelGroup style="font-size: 10">
                        <h:commandLink immediate="true"
action="#{t.toggleExpanded}">
                                        <h:graphicImage
value="/images/iminus.gif" rendered="#{t.nodeExpanded && !t.node.leaf}"
style="border: 0;color: blue"/>
                                        <h:graphicImage
value="/images/iplus.gif" rendered="#{!t.nodeExpanded && !t.node.leaf}"
style="border: 0;color: blue"/>
                                        <f:actionListener
type="com.mycompany.MyTreeBackerBean"/>
                        </h:commandLink>
                        <h:graphicImage value="/images/ibar.gif"
rendered="#{t.node.leaf}" style="border: 0"/>
                        ...
                </h:panelGroup>
        </f:facet>
        ...
</t:tree2>



public void processAction(ActionEvent event) throws
AbortProcessingException {
        UIComponent component = (UIComponent) event.getSource();
        while (!(component != null && component instanceof HtmlTree)) {
                component = component.getParent();
        }
        if (component != null) {
                HtmlTree tree = (HtmlTree) component;
                TreeNodeImpl node = (TreeNodeImpl) tree.getNode();
                if (!tree.isNodeExpanded() && node.getChildren().size()
== 0) {
                        //fetch your data
                        ...
                }
                ...
        }
        ...
}

In the above example, we used our own plus/minus GIFs.  Also, we
attached an actionListener to capture the expand/collapse event.  In the
action listener, we bubble up to the Html tree so we can get the
selected node.  Once we have that, we can check whether it's expanded or
not, and whether the children have already been fetched.  (We don't want
to do our fetch more than once.)  We only do the fetch if the node is
not expanded (and is therefore in the process of being expanded), and if
we don't yet have any children.

I understand that there have recently been some architectural changes to
Tree2; but this was developed on the original model.  It still works as
of the build for 8/15/2005.  (I haven't tried it with the latest nightly
build.)

Reply via email to