}
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
final UITreeSelect select = (UITreeSelect) component;
final AbstractUITreeNode node = ComponentUtils.findAncestor(select, AbstractUITreeNode.class);
final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
if (data instanceof AbstractUITreeListbox) {
writer.write(StringUtils.defaultString((String) select.getLabel()));
return;
}
final String id = select.getClientId(facesContext);
final String currentValue = getCurrentValue(facesContext, select);
final boolean checked;
if (select.isValueStoredInState()) {
checked = data.getSelectedState().isSelected(node.getPath());
} else {
checked = "true".equals(currentValue);
}
final boolean folder = data.isFolder();
final Selectable selectable = data.getSelectableAsEnum();
writer.startElement(HtmlElements.SPAN, null);
writer.writeClassAttribute(Classes.create(select));
HtmlRendererUtils.writeDataAttributes(facesContext, writer, select);
if (select.isShowCheckbox()
&& selectable != Selectable.NONE
&& (!selectable.isLeafOnly() || !folder)) {
writer.startElement(HtmlElements.INPUT, null);
if (selectable.isSingle()) {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.RADIO, false);
writer.writeNameAttribute(getClientIdWithoutRowIndex(data, id));
} else {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX, false);
writer.writeNameAttribute(id);
}
writer.writeAttribute(HtmlAttributes.VALUE, id, false);
writer.writeIdAttribute(id);
writer.writeAttribute(HtmlAttributes.CHECKED, checked);
writer.endElement(HtmlElements.INPUT);
}
// label
final String label = select.getLabel();
if (StringUtils.isNotEmpty(label)) {
writer.startElement(HtmlElements.LABEL, null);
writer.writeClassAttribute(Classes.create(select, "label"));
HtmlRendererUtils.renderTip(select, writer);
writer.writeAttribute(HtmlAttributes.FOR, id, false);