jsf2战斧selectOneRadio分别渲染标签 [英] jsf2 tomahawk selectOneRadio render label separately

查看:41
本文介绍了jsf2战斧selectOneRadio分别渲染标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tomahawk radio control满足我的设计要求.我正在测试,想问是否有人回答.

I am using Tomahawk radio control for my design requirement. I was testing and wanted to ask if someone answer please.

 <t:selectOneRadio id="myRadio" forceId="true" layout="spread" styleClass="field checkbox">
                                    <f:selectItems value="#{personBean.genders}"  />
                                </t:selectOneRadio>
                                <c:forEach items="#{personBean.genders}" varStatus="loop">
                                    <span style="width:80px;" class="checkbox"><t:radio for=":myForm:myRadio"  index="#{loop.index}" /></span>
                                </c:forEach>

生成的HTML

<span class="checkbox"><input type="radio" class="field checkbox" value="male" name="myRadio" id="myForm:j_idt35"><label for="myForm:j_idt35"> male</label></span>

问题:

我想在带有复选框的male上使用class属性.可以单独渲染吗?

我可以像下面那样应用样式,但是我希望Label单独呈现以具有更多控制权.

I can apply style like below but I want Label to render separately to have more control.

.checkbox label {
    display: block;
    cursor: pointer;
    font-size: 100%;
    line-height: 150%;
    margin: -17px 0 0 18px;
    padding: 0 0 5px 0;
    color: #222;
    width: 88%
}

推荐答案

查看源代码,不是.

不过,您可以使用+设置样式:

You could however style it with +:

input[type='checkbox'] + label {
    display: block;
    cursor: pointer;
    font-size: 100%;
    line-height: 150%;
    margin: -17px 0 0 18px;
    padding: 0 0 5px 0;
    color: #222;
    width: 88%
}

如果要以其他方式呈现它,则需要重写HtmlRadioRenderer:

If would like to render it differently, you need to override HtmlRadioRenderer:

将此内容放入faces-config.xml:

  <renderer>
    <component-family>javax.faces.SelectOne</component-family>
    <renderer-type>org.apache.myfaces.Radio</renderer-type>
    <renderer-class>your-renderer-class</renderer-class>
  </renderer>

创建一个类your-renderer-class.java,在org.apache.myfaces.renderkit.html.ext.HtmlRadioRenderer中进行覆盖,您很高兴.

Create a class your-renderer-class.java, override in in org.apache.myfaces.renderkit.html.ext.HtmlRadioRenderer and you are good to go.

在网上阅读有关此操作的信息:

Read the web on how this is done: JSF 2.0: How to override base renderers with custom ones?

这篇关于jsf2战斧selectOneRadio分别渲染标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆