Digging into the RadioRenderer
source code I've noticed the following thing:
The method
@Override
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
Object currentSelections,
Object[] submittedValues,
boolean alignVertical,
int itemNumber,
OptionComponentInfo optionInfo) throws IOException
overriden in the RadioRenderer
class is being called from the standard public void encodeEnd(FacesContext context, UIComponent component)
Renderer method. But there was the following piece of code:
Iterator<SelectItem> items =
RenderKitUtils.getSelectItems(context, component);
//some code
while (items.hasNext()) {
SelectItem curItem = items.next();
idx++;
// If we come across a group of options, render them as a nested
// table.
if (curItem instanceof SelectItemGroup) {
// do some
else {
// do another
}
}
So, I tried it by the example:
<h:selectOneRadio>
<f:selectItem />
<f:selectItems value="#{myBean.vals}" />
<f:selectItems value="#{myBean.valss}" />
</h:selectOneRadio>
and the selectItem
and the selectItems
es were treated as not the instances of the SelectItemGroup
. For selectItem
that's perfectly clear, but I expected that selectItems
would be mapped to the SelectItemGroup
instance.
Couldn't you clarify the thing a bit?
It can not declaratively be created. It can only programmatically be created. The
<f:selectItems>
also supportsList<SelectItem>
withjavax.faces.model.SelectItem
instances of which theSelectItemGroup
is a subclass. Below is an extract of relevance of its javadoc:Here's a basic example of how you can create them:
Inside
<h:selectOneRadio>
it will render as a nested table (which is IMHO a poor rendering, they'd better have rendered the group label as a<thead>
, but that aside). It's best visible when you setlayout
topageDirection
, otherwise everything will appear in a single line (lineDirection
).And inside the
<h:selectOneMenu>
it will render as a tree with option values nested in<optgroup>
(which is actually the primary use case forSelectItemGroup
):The
<h:selectManyListbox>
also supports it (the<h:selectOneListbox>
has exactly the same rendering, but supports only a single selection):The
<h:selectManyCheckbox>
has the same (semantically awkward) nested table rendering as<h:selectOneRadio>
:The
<h:selectManyMenu>
isn't useful at all, so I'll skip it.See also:
selectOneMenu
wiki page