UIComponent component, Converter converter, Set lookupSet,
List selectItemList) throws IOException {
ResponseWriter writer = context.getResponseWriter();
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_impl.renderkit.RendererUtils.getConvertedStringValue(context, component,
converter, selectItem);
writer.write(TABULATOR);
writer.startElement(HTML.OPTION_ELEM, component);
if (itemStrValue != null) {
writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
}
if (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
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;
boolean componentDisabled = isTrue(component.getAttributes().get("disabled"));
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);
}