private static final String MENU_ACCELERATOR_KEYS = "menuAcceleratorKeys";
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
UIMenuCommand menu = (UIMenuCommand) component;
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
boolean disabled = menu.isDisabled();
boolean firstLevel = RendererTypes.MENU_BAR.equals(menu.getParent().getRendererType());
LabelWithAccessKey label = new LabelWithAccessKey(menu);
String clientId = menu.getClientId(facesContext);
String submit = HtmlRendererUtils.createSubmitAction(clientId, true, null, null);
if (menu.getFacet(Facets.CHECKBOX) != null) {
// checkbox menu
UISelectBooleanCheckbox checkbox = (UISelectBooleanCheckbox) menu.getFacet(Facets.CHECKBOX);
boolean checked = ComponentUtils.getBooleanAttribute(checkbox, Attributes.VALUE);
String image = checked ? "image/MenuCheckmark.gif" : null;
String hiddenId = checkbox.getClientId(facesContext);
// the function toggles true <-> false
String setValue = JQueryUtils.selectId(hiddenId)
+ ".each(function(){$(this).val($(this).val() == 'true' ? 'false' : 'true')}); ";
encodeItem(facesContext, writer, menu, label, setValue + submit, disabled, firstLevel, image);
encodeHidden(writer, hiddenId, checked);
} else if (menu.getFacet(Facets.RADIO) != null) {
// radio menu
UISelectOne radio = (UISelectOne) menu.getFacet(Facets.RADIO);
List<SelectItem> items = RenderUtils.getSelectItems(radio);
String hiddenId = radio.getClientId(facesContext);
for (SelectItem item : items) {
boolean checked = item.getValue().equals(radio.getValue());
String image = checked ? "image/MenuRadioChecked.gif" : null;