Previous Section  < Day Day Up >  Next Section

Chapter 13. Developing Custom Renderers and Other Pluggable Classes

The JSF specification includes the basic components most applications need: simple input and output, selection lists, menus and checkboxes, links and buttons, a data grid, and panels for layout. When the provided set of components isn't enough, I recommend that you first look around to see if someone else has developed the component you need. At the time of this writing there are already open source components for the Proposed Final Draft specification version, and when the final specification version is released and JSF gains in popularity, I'm sure there will be plenty of both free and commercial components to pick from. Keep an eye on Sun's JSF site at http://java.sun.com/j2ee/javaserverfaces for references to ready-made components.

If you can't find what you're looking for, you need to roll up your sleeves and develop your own components. As you probably recall, JSF uses separate classes for a component's behavior and for component rendering. The component classes implement render-independent behavior, such as pushing and pulling the component value to and from a model property, validating an input value, and firing events. The standard components delegate the tasks of generating content to represent the component in a form suitable for a client device (e.g., as HTML elements for a browser) and figuring out how to decode the request data to get the submitted value for the component to a renderer.

In many cases, you only need to develop a custom renderer for one of the standard components to get the custom behavior you want. For instance, whether you want your users to enter a date by picking it from a calendar, selecting a year, month, and day from three menus, or to write it as a complete date string, the component's behavior—pushing the entered value to the model on submit and pulling it from the model for display—remains the same, so there's no need to develop a custom component. All that's needed is a renderer that generates the content to represent the component value in the desired format. The same is true for more complex components, such as alternative displays of tabular data. Only when you need a component with render-independent behavior not provided by the standard components do you need to implement a custom component class. We will look at examples of custom renderers in this chapter and custom components in Chapter 14.

Besides custom component and renderer classes, JSF allows you to replace most of the infrastructure classes, such as the classes used for evaluation of JSF EL expressions and for navigation. At the end of this chapter, we take a brief look at when you may want to replace some of these classes and how to do it.

    Previous Section  < Day Day Up >  Next Section