protected boolean encodeOption(FacesContext context, SelectOneMenu component, SelectItem option, Object values, Object submittedValues,
                                   Converter converter, int itemIndex) throws IOException {

        ResponseWriter writer = context.getResponseWriter();

        if (option instanceof SelectItemGroup) {
            SelectItemGroup group = (SelectItemGroup) option;

            writer.startElement("optgroup", null);
            writer.writeAttribute("label", group.getLabel(), null);
            if (group.isDisabled()) {
                writer.writeAttribute("disabled", "disabled", null);
            }
            writer.writeAttribute("data-escape", String.valueOf(group.isEscape()), null);
            if (option.getDescription() != null) {
                writer.writeAttribute("data-title", option.getDescription(), null);
            }
            for (SelectItem groupItem : group.getSelectItems()) {
                encodeOption(context, component, groupItem, values, submittedValues, converter, itemIndex);
            }
            writer.endElement("optgroup");

            return false;
        }
        else {
            String itemValueAsString = getOptionAsString(context, component, converter, option.getValue());
            boolean disabled = option.isDisabled();
            boolean isEscape = option.isEscape();
            boolean isNoSelectionOption = option.isNoSelectionOption();

            Object valuesArray;
            Object itemValue;
            if (submittedValues != null) {
                valuesArray = submittedValues;
                itemValue = itemValueAsString;
            }
            else {
                valuesArray = values;
                itemValue = option.getValue();
            }

            boolean selected = isSelected(context, component, itemValue, valuesArray, converter);

            if (!component.isDynamic() || (component.isDynamic() && (selected || component.isDynamicLoadRequest(context) || itemIndex == 0))) {
                writer.startElement("option", getSelectItemComponent(option));
                writer.writeAttribute("value", itemValueAsString, null);
                if (disabled) {
                    writer.writeAttribute("disabled", "disabled", null);
                }
                if (selected) {
                    writer.writeAttribute("selected", "selected", null);
                }
                if (isNoSelectionOption) {
                    writer.writeAttribute("data-noselection-option", "true", null);
                }
                writer.writeAttribute("data-escape", String.valueOf(isEscape), null);
                if (option.getDescription() != null) {
                    writer.writeAttribute("data-title", option.getDescription(), null);
                }

                writer.writeText(getOptionLabel(option), null);

                writer.endElement("option");
            }

            return selected;
        }
    }
Encodes one SelectItem.
@return true if SelectItem is selected.
@throws IOException
primefaces/src/main/java/org/primefaces/component/selectonemenu/SelectOneMenuRenderer.java