Registering a Custom Component
In addition to registering custom renderers (as explained in the preceding section), you also must register the custom components that are usually associated with the custom renderers.
Here is the
componentelement from the application configuration resource file that registersAreaComponent:<component> <component-type>DemoArea</component-type> <component-class> components.AreaComponent </component-class> <property> <property-name>alt</property-name> <property-class>java.lang.String</property-class> </property> <property> <property-name>coords</property-name> <property-class>java.lang.String</property-class> </property> <property> <property-name>shape</property-name> <property-class>java.lang.String</property-class> </property> <component-extension> <component-family>Area</component-family> <renderer-type>DemoArea</renderer-type> </component-extension> </component>The
component-typeelement indicates the name under which the component should be registered. Other objects referring to this component use this name. For example, thecomponent-typeelement in the configuration forAreaComponentdefines a value ofDemoArea, which matches the value returned by theAreaTagclass'sgetComponentTypemethod.The
component-classelement indicates the fully qualified class name of the component. Thepropertyelements specify the component properties and their types.If the custom component can include facets, you can configure the facets in the component configuration using
facetelements, which are allowed after thecomponent-classelements. See Registering a Custom Renderer with a Render Kit for further details on configuring facets.The
component-extensionelement identifies a component family and a renderer type. The component family represents a component or set of components that a renderer can render. The renderer type specifies the renderer that can render the components included in the component family.The component family specified by the
component-familyelement must match that returned by the components'getFamilymethods. Therenderer-typemust match that returned by the tag handler'sgetRendererTypemethod. By using the component family and renderer type to look up renderers for components, the JavaServer Faces implementation allows a component to be rendered by multiple renderers and allows a renderer to render multiple components.