// the options
List optionsList = getOptionList();
if (!optionsList.isEmpty()) {
int i = -1;
for (Iterator it = optionsList.iterator(); it.hasNext();) {
Option option = (Option) it.next();
i++;
final String liId = getName() + "_" + i;
buffer.append("<li>");
if (sortable) {
buffer.elementStart("div");
buffer.appendAttribute("style", "cursor:move;");
} else {
buffer.elementStart("label");
buffer.appendAttribute("for", liId);
}
buffer.appendAttribute("class", "checkListLabel");
buffer.closeTag();
buffer.append("<input type=\"checkbox\" ");
buffer.appendAttributeEscaped("value", option.getValue());
buffer.appendAttribute("id", liId);
buffer.appendAttribute("name", getName());
if (sortable) {
buffer.appendAttribute("style", "cursor:default;");
}
// set checked status
List values = getSelectedValues();
for (int k = 0; k < values.size(); k++) {
if (String.valueOf(values.get(k)).equals(option.getValue())) {
buffer.appendAttribute("checked", "checked");
}
}
if (isDisabled()) {
buffer.appendAttributeDisabled();
}
if (isReadonly()) {
buffer.appendAttributeReadonly();
}
buffer.elementEnd();
buffer.appendEscaped(option.getLabel());
if (sortable) {
buffer.append("</div>");
} else {
buffer.append("</label>");
}
// hiddenfield if sortable
if (sortable) {
buffer.append("<input type=\"hidden\"");
buffer.appendAttribute("name", getName() + "_order");
buffer.appendAttributeEscaped("value", option.getValue());
buffer.elementEnd();
}
buffer.append("</li>");
}