Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Working with <ui:include> and <ui:param>


The <ui:include> and <ui:param> tags are two tag handlers that can be used for accomplishing many kinds of tasks; as long as we keep in mind that tag handlers are efficient only when the view tree is built, we can exploit them for our benefit. For example, we can use them to generate a tree node structure as shown in the following screenshot:

In order to accomplish this task, we will spice up the <ui:include> and <ui:param> tags with a dash of JSTL (the <c:if> and <c:forEach> tag handlers) and recursivity.

First, we need a class that represents the abstractization of the tree node concept. Basically, a tree node representation is a hierarchical structure of labels that can be recursively traversed. Based on this, we can write a generic tree node class as shown in the following code:

public class GenericTreeNode {

  private final List<GenericTreeNode> descendants;
  private final String label;

 ...