I want to create a customized renderer for a built-in component: <h:selectOneRadio />
I would like to know, how do I determine the renderer for a built-in component in order to create my own one and extend from it?
I would like to know a mechanism to get it so I could apply it to determine the renderer for any other built-in component and not just for <h:selectOneRadio />.
thanks
The renderer class of a standard JSF component is implementation specific (Mojarra and MyFaces have each its own implementation) and is registered as
<renderer>in the implementation-specificfaces-config.xml(or an artifact of it).To find it out, you basically need to know the component family and renderer type first, so that you can lookup the renderer class in the implementation-specific
faces-config.xmlfile youself.Your starting point is the
javax.faces.component.htmlpackage summary. The<h:selectOneRadio>is represented by theHtmlSelectOneRadiocomponent class. The introductory text of its javadoc says:There is the renderer type.
The component family is specified as
COMPONENT_FAMILYconstant under "Fields inherited fromUISelectOne" section of the very same javadoc. Click through to "Constant field values":There is the component family.
Now, we should look in the implementation-specific
faces-config.xmlfile (or an artifact of it). Its location/name is unfortunately nowhere documented, but I can tell that in case of Mojarra it is thecom/sun/faces/jsf-ri-runtime.xmlfile in the implementation JAR file (you can extract JAR files with a zip tool). Open it and look for a<renderer>entry matching the component familyjavax.faces.SelectOneand renderer typejavax.faces.Radio:Finally there is it: the
com.sun.faces.renderkit.html_basic.RadioRenderer.Please note that extending exactly that class tight couples your custom renderer to the specific JSF implementation. Your renderer would not be reuseable on a different implementation such as MyFaces. To be implementation independent, you’d need to write the entire renderer yourself which extends
javax.faces.renderer.Renderer.See also: