jump to navigation

Creating a lazy-loading tree with IceFaces July 7, 2008

Posted by Phill in Frameworks, Presentation Layer.
Tags: ,

I tried a number of things to make a lazy-loaded tree in IceFaces, but I couldn’t quite get it to work. There are probably better ways of doing it, but I found something which is pretty easy: when you create your lazy-loaded TreeNodes, for each node which hasn’t had its children loaded yet just create a dummy child. In other words, if you don’t want a node to be lazy-loaded, just add a TreeNode child in which says something like “Loading…”. You will also need to subclass DefaultMutableTreeNode to add in a boolean property – something like childrenLoaded.

Then, in your JSF page, set the tree actionListener property to be “#{beanName.expandListener}” and create the relevant method in your backing bean:

public void expand( ActionEvent e )
        Tree tree = (Tree) e.getSource();

        TreeNode node = tree.getNavigatedNode();
        if ("expand".equals( tree.getNavigationEventType() ))
            _treeModel.loadChildren( node );

… assuming, of course, that your TreeModel has a “loadChildren” method on it. Your mileage may vary. You will, of course, need to check whether the children have already been loaded for that node. But it’s still probably the easiest method that I’ve found so far!



1. jsf naive - November 19, 2009

can youi please explain this in more detail?

2. Phill - December 2, 2009

Note that the expand method above should be “expandListener”.

JSF naive, the idea is that when a user clicks the “expand” icon, the “expandListener” method will be called.

This will then load up any necessary children from the TreeModel.

Sorry comments are closed for this entry

%d bloggers like this: