如何覆盖 h:selectOneRadio 渲染器?jsf-impl 中的渲染器类在哪里? [英] How to override h:selectOneRadio renderer? Where is the renderer class in jsf-impl?
问题描述
是否可以覆盖
使用的渲染器?我试图从 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,则是 com.sun.faces.renderkit.html_basic.RadioRenderer
类.如果是 MyFaces,则是 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 实现/版本紧密耦合.这种扩展的渲染器与不同的 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.
我想这样做的原因是为了摆脱它生成的表.
考虑查看 Tomahawk 或 PrimeFaces 而不是重新发明轮子.它们分别有一个 <t:selectOneRadio layout="传播><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 中的渲染器类在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!