Now that we are done with the basics of what a JSF component is, let's see the simplest example of a JSF custom component, the HelloWorld component. The idea of this recipe is to get you familiar with the skeletons of the JSF custom component classes.
We have developed this recipe with NetBeans 6.8, JSF 2.0, and GlassFish v3. The JSF 2.0 classes were obtained from the NetBeans JSF 2.0 bundled library.
We will proceed step by step, and implement each class described earlier in the introduction of the chapter. To begin with, we will write the UI Component class, and for this we keep in mind that the effect of our component is to render a simple message on the client. Knowing that, we can extend the concrete UIOutput
class or, as we did, the UIComponentBase
class (we prefer this class, because we don't need the value
attribute, which is specific for UIOutput
components). Therefore, our component may look as shown next:
package...