本文介绍了如何确定内置组件的渲染器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为内置组件创建自定义渲染器:<h:selectOneRadio />我想知道,如何确定内置组件的渲染器,以便创建自己的组件并从中扩展?

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?

我想知道一种获取它的机制,因此我可以将其应用于确定任何其他内置组件的渲染器,而不仅仅是确定<h:selectOneRadio />的渲染器.

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 />.

谢谢

推荐答案

标准JSF组件的呈现器类特定于实现(Mojarra和MyFaces各自具有自己的实现),并在特定于实现的情况下注册为<renderer> faces-config.xml(或它的工件).

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).

要找出答案,您基本上首先需要了解组件系列和渲染器类型,以便您可以自己在实现特定的faces-config.xml文件中查找渲染器类.

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.

您的起点是 javax.faces.component.html包裹摘要. <h:selectOneRadio> 组件类. 其Javadoc 的介绍性文本说:

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:

存在渲染器类型.

在.单击以访问常量字段值" :

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":

有组件族.

现在,我们应该查看特定于实现的faces-config.xml文件(或其文件).不幸的是,它的位置/名称没有记录在任何地方,但是我可以确定,在Mojarra的情况下,它是实现JAR文件中的com/sun/faces/jsf-ri-runtime.xml文件(您可以使用zip工具提取JAR文件).打开它并查找与组件族javax.faces.SelectOne和渲染器类型javax.faces.Radio相匹配的<renderer>条目:

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>

最后是它: com.sun.faces.renderkit.html_basic.RadioRenderer .

Finally there is it: the com.sun.faces.renderkit.html_basic.RadioRenderer.

请注意,正是严格地扩展了该类,才能将您的自定义渲染器与特定的JSF实现耦合.您的渲染器无法在其他实现(例如MyFaces)上重复使用.为了实现独立,您需要自己编写扩展javax.faces.renderer.Renderer的整个渲染器.

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.

  • How to findout component-family and renderer-type of a JSF component
  • What is the relationship between component family, component type and renderer type?

这篇关于如何确定内置组件的渲染器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:33