When I am learning custom component development in JSF, I got confused with the relationship between component family, component type and renderer type. For example, I registered a renderer and a custom component as shown below.
faces-config.xml
:
<component>
<component-type>study.faces.Div</component-type>
<component-class>javax.faces.component.UIPanel</component-class>
</component>
<render-kit>
<render-kit-id>HTML_BASIC</render-kit-id>
<renderer>
<component-family>javax.faces.Panel</component-family>
<renderer-type>study.faces.DivRenderer</renderer-type>
<renderer-class>com.study.ui.DivRenderer</renderer-class>
</renderer>
</render-kit>
I also registered a new tag in my.taglib.xml
file as below:
<tag>
<tag-name>div</tag-name>
<component>
<component-type>study.faces.Div</component-type>
<renderer-type>study.faces.DivRenderer</renderer-type>
</component>
</tag>
This configuration works very well. However, I didn't understand why the line <component-family>javax.faces.Panel</component-family>
is required on renderer registration. In my.taglib.xml
, the component and the renderer is connected and, IMHO, it should have been enough to select an appropriate renderer for the component. What is the use of the additional parameter <component-family>
?
I did Google researches and all the answers I got say like "One renderer can be used to render multiple components. These components belong to one family". But these statements didn't clear my confusion up. Can someone explain the relationship between component type, component family and renderer selection strategy? (Hopefully with a good example.)