logo
Home Tutorial

How To Create Your Own Java Server Faces Components



In this tutorial we have created new Java Server Faces components all the way from scratch to a deployable package. In this example, we have covered the major points you will need in order to create any Java Server Faces component. However, our example does not show all of the aspects of Java Server Faces component building. You now have just the basic knowledge. If writing Java Server Faces components is going to be your job, you will need to learn more before you will become an expert in this area.

Additional Topics

Some of the aspects you will need to learn that were not covered in this tutorial are mentioned below.

Processing user input. If your component accepts data entered or selected by the user, you need to take care of encoding or decoding the date. Such a component might need to support validators, value changed listener, data converters.

Working with Facets. Facets are similar to children, but they have names. It is up to the component how to process them. For example, the gridPanel from the standard Java Server Faces library has two facet elements for header and footer. It does not matter where the facet is located in the JSP code, the renderer always puts the header at the top and footer at the bottom.

Custom rendering of the existing components. In our example, the getRendererType method of the TickerTag returns null. This means that the component renders itself. If this method returns any value, it makes it possible to overwrite the default rendering provided by the UITicker class. For this purpose, you or anybody else can add a new renderer with the defined name to the render-kit section of the faces configuration file. In the same way, you can implement rendered for any standard JSF components. All of the render type names can be found in the JSF specification.

Action components. You can extend your component from the UICommand class. This allows you to write components similar to a command button or a link, but with advanced behavior. For example, you can implement tabbed panels or drop-down menus.

See Also:

Guidelines for Designing Reusable Custom Components Using JavaServer Faces Technology


This article gives you some basic guidelines for designing
custom components using ChartComponent as an example.


Creating JSF Custom Components by Bill Dudney


This article illustrates how to build custom components for use
in web applications based on JavaServer Faces (JSF).