如何覆盖h:selectOneRadio渲染器? jsf-impl中的renderer类在哪里? [英] How to override h:selectOneRadio renderer? Where is the renderer class in jsf-impl?
问题描述
是否可以覆盖<h:selectOneRadio>
使用的渲染器?我试图从JSF 2.2的jsf-impl包中找到该类,但没有找到.我想这样做的原因是摆脱了它生成的表.
Is it possible to override renderer used by <h:selectOneRadio>
? I tried to find the class from jsf-impl package of JSF 2.2 but didn't find it. The reason I want to do this is to get rid of the table it generates.
推荐答案
是否可以覆盖h:selectOneRadio使用的渲染器?
是的,肯定是的.否则,诸如PrimeFaces之类的UI组件库将不存在.
Yes, surely it is. Otherwise, UI component libraries like PrimeFaces couldn't exist.
我试图从jsf-impl包中找到该类,但没有找到.
确切的类取决于您使用的JSF实现.如果是Mojarra,则为 org.apache.myfaces.renderkit.html.HtmlRadioRenderer
类.
The exact class depends on the JSF implementation you're using. If it's Mojarra, then it's the com.sun.faces.renderkit.html_basic.RadioRenderer
class. If it's MyFaces, then it's the org.apache.myfaces.renderkit.html.HtmlRadioRenderer
class.
为了正确地覆盖它,只需在必要时扩展类和覆盖方法,然后在faces-config.xml
中注册它,如下所示:
In order to properly override it, just extend the class and override methods where necessary and register it as follows in your faces-config.xml
:
<render-kit>
<renderer>
<component-family>javax.faces.SelectOne</component-family>
<renderer-type>javax.faces.Radio</renderer-type>
<renderer-class>com.example.MyRadioRenderer</renderer-class>
</renderer>
</render-kit>
请记住,您是通过这种方式将渲染器紧密耦合到特定的JSF impl/version.这种扩展的渲染器与其他JSF实现不兼容(即,当您用MyFaces替换Mojarra时,您的应用将无法部署),并且可能在当前JSF实现已更新为较新版本时中断.如果您对此感到担心,请考虑完全从头开始编写渲染器,例如PrimeFaces等.做.
Keep in mind that you're this way tight-coupling the renderer to the specific JSF impl/version. Such an extended renderer is not compatible with a different JSF implementation (i.e. your app wouldn't deploy when you ever replace Mojarra by MyFaces) and may possibly break when the current JSF implementation has been updated to a newer version. If you worry about this, consider writing the renderer entirely from scratch, like PrimeFaces et.al. do.
我要这样做的原因是摆脱它生成的表.
考虑查看战斧或 PrimeFaces ,而不是重新发明轮子.它们分别具有 <t:selectOneRadio layout="spread"><t:radio>
和 <p:selectOneRadio layout="custom"><p:radioButton>
允许您将这些内容放置在所需的任何位置.
Consider looking at Tomahawk or PrimeFaces instead of reinventing the wheel. They have respectively a <t:selectOneRadio layout="spread"><t:radio>
and <p:selectOneRadio layout="custom"><p:radioButton>
which allows you positioning those things everywhere you want.
这篇关于如何覆盖h:selectOneRadio渲染器? jsf-impl中的renderer类在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!