protected void encodeOption(
      FacesContext context,
      SelectCheckboxMenu menu,
      Object values,
      Object submittedValues,
      Converter converter,
      SelectItem option,
      int idx)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, menu, converter, option.getValue());
    String name = menu.getClientId(context);
    String id = name + UINamingContainer.getSeparatorChar(context) + idx;
    boolean disabled = option.isDisabled() || menu.isDisabled();

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

    boolean checked = isSelected(context, menu, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !checked) {
      return;
    }

    // input
    writer.startElement("input", null);
    writer.writeAttribute("id", id, null);
    writer.writeAttribute("name", name, null);
    writer.writeAttribute("type", "checkbox", null);
    writer.writeAttribute("value", itemValueAsString, null);

    if (checked) writer.writeAttribute("checked", "checked", null);
    if (disabled) writer.writeAttribute("disabled", "disabled", null);
    if (menu.getOnchange() != null) writer.writeAttribute("onchange", menu.getOnchange(), null);

    writer.endElement("input");

    // label
    writer.startElement("label", null);
    writer.writeAttribute("for", id, null);
    if (disabled) writer.writeAttribute("class", "ui-state-disabled", null);

    if (option.isEscape()) writer.writeText(option.getLabel(), null);
    else writer.write(option.getLabel());

    writer.endElement("label");
  }
  protected void encodeOption(
      FacesContext context,
      SelectOneListbox listbox,
      SelectItem option,
      Object values,
      Object submittedValues,
      Converter converter)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue());
    boolean disabled = option.isDisabled() || listbox.isDisabled();

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

    boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !selected) {
      return;
    }

    writer.startElement("option", null);
    writer.writeAttribute("value", itemValueAsString, null);
    if (disabled) writer.writeAttribute("disabled", "disabled", null);
    if (selected) writer.writeAttribute("selected", "selected", null);

    if (option.isEscape()) {
      writer.writeText(option.getLabel(), null);
    } else {
      writer.write(option.getLabel());
    }

    writer.endElement("option");
  }
  protected void encodeItem(
      FacesContext context,
      SelectOneListbox listbox,
      SelectItem option,
      Object values,
      Object submittedValues,
      Converter converter,
      boolean customContent)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue());
    boolean disabled = option.isDisabled() || listbox.isDisabled();
    String itemClass =
        disabled ? SelectOneListbox.ITEM_CLASS + " ui-state-disabled" : SelectOneListbox.ITEM_CLASS;

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

    boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !selected) {
      return;
    }

    if (selected) {
      itemClass = itemClass + " ui-state-highlight";
    }

    if (customContent) {
      String var = listbox.getVar();
      context.getExternalContext().getRequestMap().put(var, option.getValue());

      writer.startElement("tr", null);
      writer.writeAttribute("class", itemClass, null);
      if (option.getDescription() != null) {
        writer.writeAttribute("title", option.getDescription(), null);
      }

      for (UIComponent child : listbox.getChildren()) {
        if (child instanceof Column && child.isRendered()) {
          writer.startElement("td", null);
          renderChildren(context, child);
          writer.endElement("td");
        }
      }

      writer.endElement("tr");
    } else {
      writer.startElement("li", null);
      writer.writeAttribute("class", itemClass, null);
      if (option.isEscape()) {
        writer.writeText(option.getLabel(), null);
      } else {
        writer.write(option.getLabel());
      }

      writer.endElement("li");
    }
  }