Tree From Database, With Zones

JavaScript is not enabled in your browser. Please enable JavaScript for this page to work properly.
Here we demonstrate Tapestry's Tree component built from data in the database. When you click on a leaf, its info is displayed in a Zone.

The data is a partial list of the Dewey Decimal Classifications.
It is stored in table Classification.
Each Classification can have "child" Classifications. By definition, the leaf Classifications have no children, and the root Classifications have no parent.
ClassificationNode is a convenience wrapper around a Classification, summarising whether it has children or is instead a leaf.

Tree is actually an AJAX component. When you expand or collapse a node it sends event EXPAND_CHILDREN or MARK_COLLAPSED via AJAX.
If you have provided a selectionModel (we have not), when you click a leaf the Tree sends event NODE_SELECTED or NODE_UN_SELECTED.
These events bubble up, so you can add your own event handlers for them.

In this example we did not use a selectionModel. Instead, we overrode the label block with our own and embedded an AJAX EventLink because:

EventLink renders returned Zones, whereas Tree ignores Zones returned from NODE_SELECTED and NODE_UN_SELECTED.

Tree's selectionModel enables multiple nodes to be selected. Its purpose seems to be to gather your selections until a submit.