boolean hideNoSelectionOption = isHideNoSelectionOption(component);
boolean componentDisabled = isTrue(component.getAttributes()
.get("disabled"));
for (Iterator it = selectItemList.iterator(); it.hasNext();)
{
SelectItem selectItem = (SelectItem) it.next();
if (selectItem instanceof SelectItemGroup)
{
writer.startElement(HTML.OPTGROUP_ELEM, component);
writer.writeAttribute(HTML.LABEL_ATTR, selectItem.getLabel(),
null);
SelectItem[] selectItems = ((SelectItemGroup) selectItem)
.getSelectItems();
renderSelectOptions(context, component, converter, lookupSet,
Arrays.asList(selectItems));
writer.endElement(HTML.OPTGROUP_ELEM);
}
else
{
String itemStrValue = org.apache.myfaces.shared.renderkit.RendererUtils
.getConvertedStringValue(context, component, converter,
selectItem);
boolean selected = lookupSet.contains(itemStrValue);
//TODO/FIX: we always compare the String vales, better fill lookupSet with Strings
//only when useSubmittedValue==true, else use the real item value Objects
// IF the hideNoSelectionOption attribute of the component is true
// AND this selectItem is the "no selection option"
// AND there are currently selected items
// AND this item (the "no selection option") is not selected
// (if there is currently no value on UISelectOne, lookupSet contains "")
if (hideNoSelectionOption && selectItem.isNoSelectionOption()
&& lookupSet.size() != 0
&& !(lookupSet.size() == 1 && lookupSet.contains(""))
&& !selected)
{
// do not render this selectItem
continue;
}
writer.write(TABULATOR);
writer.startElement(HTML.OPTION_ELEM, component);
if (itemStrValue != null)
{
writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
}
else
{
writer.writeAttribute(HTML.VALUE_ATTR, "", null);
}
if (selected)
{
writer.writeAttribute(HTML.SELECTED_ATTR, HTML.SELECTED_ATTR, null);
}
boolean disabled = selectItem.isDisabled();
if (disabled)
{
writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
}
String labelClass = null;
if (componentDisabled || disabled)
{
labelClass = (String) component.getAttributes().get(
JSFAttr.DISABLED_CLASS_ATTR);
}
else
{
labelClass = (String) component.getAttributes().get(
JSFAttr.ENABLED_CLASS_ATTR);
}
if (labelClass != null)
{
writer.writeAttribute("class", labelClass, "labelClass");
}
boolean escape;
if (component instanceof EscapeCapable)
{
escape = ((EscapeCapable) component).isEscape();
// Preserve tomahawk semantic. If escape=false
// all items should be non escaped. If escape
// is true check if selectItem.isEscape() is
// true and do it.
// This is done for remain compatibility.
if (escape && selectItem.isEscape())
{
writer.writeText(selectItem.getLabel(), null);
}
else
{
writer.write(selectItem.getLabel());
}
}
else
{
escape = RendererUtils.getBooleanAttribute(component,
JSFAttr.ESCAPE_ATTR, false);
//default is to escape
//In JSF 1.2, when a SelectItem is created by default
//selectItem.isEscape() returns true (this property
//is not available on JSF 1.1).
//so, if we found a escape property on the component
//set to true, escape every item, but if not
//check if isEscape() = true first.
if (escape || selectItem.isEscape())
{
writer.writeText(selectItem.getLabel(), null);
}
else
{
writer.write(selectItem.getLabel());
}
}
writer.endElement(HTML.OPTION_ELEM);
}