private static final Logger LOG = LoggerFactory.getLogger(MenuCommandRenderer.class);
@Override
public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
final UIMenuCommand menu = (UIMenuCommand) component;
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final boolean disabled = menu.isDisabled();
final boolean firstLevel = RendererTypes.MENU_BAR.equals(menu.getParent().getRendererType());
if (menu.getFacet(Facets.CHECKBOX) != null) {
// checkbox menu
final UISelectBooleanCheckbox checkbox = (UISelectBooleanCheckbox) menu.getFacet(Facets.CHECKBOX);
final boolean checked = ComponentUtils.getBooleanAttribute(checkbox, Attributes.VALUE);
final String image = checked ? "image/MenuCheckmark.gif" : null;
final String hiddenId = checkbox.getClientId(facesContext);
final CommandMap map = new CommandMap(new Command());
final LabelWithAccessKey label = new LabelWithAccessKey(menu);
encodeItem(facesContext, writer,
menu, label, map, disabled, firstLevel, image, null, "selectBoolean", menu.getClientId());
encodeHidden(writer, hiddenId, checked);
} else if (menu.getFacet(Facets.RADIO) != null) {
// radio menu
final String clientId = menu.getClientId(facesContext);
final UISelectOne radio = (UISelectOne) menu.getFacet(Facets.RADIO);
final String hiddenId = radio.getClientId(facesContext);
for (final SelectItem item : SelectItemUtils.getItemIterator(facesContext, radio)) {
final boolean checked = ObjectUtils.equals(item.getValue(), radio.getValue());
final String image = checked ? "image/MenuRadioChecked.gif" : null;
final String labelText = item.getLabel();
final LabelWithAccessKey label = new LabelWithAccessKey(labelText);
final String formattedValue = RenderUtils.getFormattedValue(facesContext, radio, item.getValue());
final CommandMap map = new CommandMap(
new Command(clientId, null, null, null, null, null, null, null, null, null));
encodeItem(
facesContext, writer, null, label, map, disabled, firstLevel, image, formattedValue, "selectOne", clientId);
}
encodeHidden(writer, hiddenId, getCurrentValue(facesContext, radio));
} else {
// normal menu command
final String image = menu.getImage();
final CommandMap map = new CommandMap(new Command(facesContext, menu));
final LabelWithAccessKey label = new LabelWithAccessKey(menu);
encodeItem(facesContext, writer, menu, label, map, disabled, firstLevel, image, null, null, menu.getClientId());
}
}