O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The UITree Component Class

The com.mycompany.jsf.component.UITree class is the implementation of the tree component. It’s quite similar to the standard UIData component. It uses a set of component instances defined as facets to render all objects in the model. It repeatedly calls the setNodeId() method as it traverses the tree in all request processing lifecycle phases and exposes the current node through a request scope variable, and then asks the appropriate facet for the current node to process it. The main difference is that the UITree component works with a tree structure model, while UIData works with a model of rows and columns.

The first part of the class should look familiar from the previous section:

package com.mycompany.jsf.component; import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.component.EditableValueHolder; import javax.faces.component.NamingContainer; import javax.faces.component.UIComponent; import javax.faces.component.UIComponentBase; import javax.faces.el.ValueBinding; import javax.faces.event.AbortProcessingException; import javax.faces.event.FacesEvent; import javax.faces.event.FacesListener; import javax.faces.event.PhaseId; import com.mycompany.jsf.model.TreeNode; import com.mycompany.jsf.model.TreeModel; public class UITree extends UIComponentBase ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required