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");
  }