The h:selectOneRadio renders an HTML table containing each radio button listed in f:selectItems or f:selectItem facets using most of the attributes in the h:selectOneRadio tag.
There are situations where the table layout is not desirable, such as in a table row where only one row among several may be selected. To do this with h:selectOneRadio I can place the following in each table row:
<h:selectOneRadio id="subscriptions"
value="#{subscriberBean.selectedSubscription}">
<f:selectItem id="#{subscription.id}"
itemLabel="#{subscription.name}"
itemValue="#{subscription.id}" />
</h:selectOneRadio>
There are two issues with this:1) The output of each one looks like this:
<table id="subscriptions">
<tbody>
<tr>
<td>
<input name="subscriptions" id="subscriptions:0" value="2" type="radio"><label for="subscriptions:0"> Sports</label>
</td>
</tr>
</tbody>
</table>
when all I really want is this: <input name="subscriptions" id="subscriptions:0" value="2" type="radio"><label for="subscriptions:0"> Sports</label>
Also there are many tables in my HTML output that have id="subscriptions" now which is illegal. If the h:selectOneRadio tag's existing layout attribute had a new "none" constant that rendered only the input component, then this issue would be resolved.2) I must use a f:selectItem facet which seems unnecessary when wanting to output a single UI component, and it also makes it difficult or impossible to use in facelets templates. I've tried to think of ways h:selectOneRadio could be changed to render a radio button when no h:selectItem(s) are present (like h:selectBooleanCheckbox), and using a new name/groupName attribute. I don't think that will work because h:selectOneRadio's id attribute is used as both table id and for the name attribute in each rendered input component. The value attribute would probably clash too.
What JSF really needs is an equivalent of h:selectBooleanCheckbox that renders only one input component (no table), lets me specify the name/groupName, and works with facelets. I've suggested a new component in the past and the expert group decided not to do it in JSF 2.0 because the focus should be on extensibility etc. instead of new input components. If you search on Google for jsf radio button you'll be flooded with tons and tons of people coming up with hacks for using radio buttons in JSF. Every component library also has their version of radio button that makes it usable. If I want a usable radio button I currently need to add a component suite and all of it's bloated dependencies to my pages.
I still think adding a usable radio button component should be done in JSF 2.0, but if it can't be done then my first suggestion would be a good compromise for now.
I am really interested in hearing the expert group's thoughts on this. Do you guys use JSF in production systems, and haven't you found h:selectOneRadio to be too inflexible to be useful beyond the most basic of UIs?

1 comments: