Tuesday, April 02, 2013

JSF 2.x Tip of the Day: RichFaces <rich:tree /> Component Examples

Custom TreeModel and TreeNode
I have some code that I originally wrote for a proof of concept for doing some RichFaces <rich:tree /> examples. The modified code in these examples demonstrate how to use custom TreeNode, and TreeDataModel implementations to make really nice and functional trees. The code for my generic TypedTreeNode and TreeNodesSequenceKeyModel are fully functional and can be used out of the box as the basis of your own tree implementations.

The examples include the model provided by RichFaces, my custom model (TreeNodesSequenceKeyModel), and a custom implementation of a node. The custom node is generic so you can pass in any object you like. I chose to use text, but you could use a more complex object.

The custom model, custom node, and tree are shown in the image on the right. This also has events being shown when a node is selected, or toggled.

The project was developed using NetBeans along with Apache Maven.

The project can be found on GitHub here: richfaces-tree

Note: The project has been moved to GitHub and has a couple of release versions.
  • 1.0 - Initial Release using Java EE 6
  • 1.2 - Updated functionality using Java EE 6
  • 2.0 - Updated to RichFaces 4.5.14.Final and Java EE 7.





Popular Posts