}
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
final UIMenu menu = (UIMenu) component;
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final boolean disabled = menu.isDisabled();
final boolean firstLevel = !RendererTypes.MENU.equals(menu.getParent().getRendererType());
final boolean isParentMenu = menu.getChildCount() > 0; // todo: may be not correct
writer.startElement(HtmlElements.LI, menu);
writer.writeClassAttribute(Classes.create(menu));
if (menu.getImage() != null) {
Style style = new Style();
style.setBackgroundImage("url("
+ ResourceManagerUtils.getImageOrDisabledImageWithPath(facesContext, menu.getImage(), menu.isDisabled())
+ ")");
writer.writeStyleAttribute(style);
}
writer.startElement(HtmlElements.A, menu);
writer.writeAttribute(HtmlAttributes.HREF, "#", false);
if (isParentMenu && !firstLevel) {
writer.writeClassAttribute(Classes.create(menu, "subitem-ancor"));
}
if (component != null && !component.isTransient()) {
writer.writeIdAttribute(component.getClientId(facesContext));
}
LabelWithAccessKey label = new LabelWithAccessKey(menu);
if (label.getText() != null) {
if (label.getAccessKey() != null) {
if (LOG.isInfoEnabled()
&& !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
LOG.info("duplicated accessKey : " + label.getAccessKey());
}
if (!disabled && label.getAccessKey() != null) {
writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
}
}
HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
}
writer.endElement(HtmlElements.A);
if (isParentMenu) {
if (!firstLevel) {
writer.startElement(HtmlElements.IMG, menu);
String arrow = ResourceManagerUtils
.getImageOrDisabledImageWithPath(facesContext, "image/MenuArrow.gif", menu.isDisabled());
writer.writeAttribute(HtmlAttributes.SRC, arrow, false);
writer.writeClassAttribute(Classes.create(menu, "subitem-arrow"));
writer.endElement(HtmlElements.IMG);
}
writer.startElement(HtmlElements.OL, menu);