Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

jsf 2 - How do I determine the renderer of a built-in component

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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-specific faces-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.xml file youself.

Your starting point is the javax.faces.component.html package summary. The <h:selectOneRadio> is represented by the HtmlSelectOneRadio component class. The introductory text of its javadoc says:

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

There is the renderer type.

The component family is specified as COMPONENT_FAMILY constant under "Fields inherited from UISelectOne" section of the very same javadoc. Click through to "Constant field values":

public static final java.lang.String COMPONENT_FAMILY "javax.faces.SelectOne"

There is the component family.

Now, we should look in the implementation-specific faces-config.xml file (or an artifact of it). Its location/name is unfortunately nowhere documented, but I can tell that in case of Mojarra it is the com/sun/faces/jsf-ri-runtime.xml file 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 family javax.faces.SelectOne and renderer type javax.faces.Radio:

<renderer>
    <component-family>javax.faces.SelectOne</component-family>
    <renderer-type>javax.faces.Radio</renderer-type>
    <renderer-class>
         com.sun.faces.renderkit.html_basic.RadioRenderer
    </renderer-class>
</renderer>

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...