Search code examples
jsfrenderer

How to findout component-family and renderer-type of a JSF component


How can I findout the component-family and the (default) renderer-type of a JSF component?

These information are necessary when (overriding custom renderers) using the following annotation:

@FacesRenderer(componentFamily="",rendererType="")

I Googled, went throughed the JSF specification and Ed Burn's book, but couldn't find what I wanted.


Solution

  • Programmatically, you could find them out by just printing UIComponent#getFamily() and UIComponent#getRendererType().

    Documentary, you could find them out by just looking in the javadoc of the component implementation. For example, <h:inputText> is represented by the HtmlInputText class. The renderer type can be found in the last paragraph of the introductory text of the javadoc:

    By default, the rendererType property must be set to "javax.faces.Text".

    The component family can be found by checking the value of COMPONENT_FAMILY constant field value (which is inherited from UIInput). Click your way through the Fields inherited from class javax.faces.component.UIInput - COMPONENT_FAMILY - Constant Field Values

    COMPONENT_FAMILY "javax.faces.Input"


    Unrelated to the concrete problem: you cannot override the default JSF renderers by the @FacesRenderer annotation. The default renderer would always get prededence. This is by design, see also issue 1748. You really need to register them explicitly as <renderer> in the faces-config.xml the JSF 1.x way.

    <render-kit>
        <renderer>
            <component-family>javax.faces.Input</component-family>
            <renderer-type>javax.faces.Text</renderer-type>
            <renderer-class>com.example.CustomTextRenderer</renderer-class>
        </renderer>
    </render-kit>