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