In this chapter, we will cover:
By default, JSF comes with a set of components divided into different categories. Depending on their usage, we have input components, output components, controls, buttons, menus, and so on. Every time we write a JSF page, we are using these components, such as HTML tags and so on. This happens because, in a JSF model, components are shipped with JSF and they have JSP bindings and generate HTML renderings.
As you will see over the course of the chapter, a JSF component is based on two major actions, known as decoding and encoding. These two notions are very important for you to understand how a JSF component works or how to write a new one, therefore, here are their definitions:
These actions are available through two approaches:
Now, let's take a high-level view over the JSF components lifecycle. For this we present you with the following figure, which should make things clear:
As you can see, the encoding action happens in Apply Request Values Phase, while the decoding happens in the Render Response Phase.
Now, let's make a step forward and let's talk about the implementation of JSF custom components. Let's overview the classes that we should write for creating a JSF custom component:
UIComponentBase
or an existing JSF UIComponent
. Optionally it can contain the logic to render the component, or rendering logic can be separated into another class.In this chapter, you will see a series of recipes that will show you how to implement JSF custom components, and obviously, the previous classes.
Before deciding to implement a JSF custom component, don't forget to perform a detailed search on Google (or on your favourite search engine) to see if your component is already available under some project, such as PrimeFaces, MyFaces, RichFaces, IceFaces, ADF Faces, and so on. It may spare you the trouble.