jsf2 tomahawk selectOneRadio render label separately

ε祈祈猫儿з 提交于 2019-12-12 01:13:11

问题


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 Generated

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

Question:

I want to use class attribute on male which is rendered with the checkbox. Is it possible to render it separately?

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%
}

回答1:


Looking at the source code no, it's not.

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%
}

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

Put this in 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>

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?



来源:https://stackoverflow.com/questions/13573178/jsf2-tomahawk-selectoneradio-render-label-separately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!