private static final Logger LOG = LoggerFactory.getLogger(ButtonRenderer.class);
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
final UIButton button = (UIButton) component;
final String clientId = button.getClientId(facesContext);
final boolean disabled = button.isDisabled();
final LabelWithAccessKey label = new LabelWithAccessKey(button);
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.BUTTON, button);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlButtonTypes.BUTTON, false);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, button);
HtmlRendererUtils.renderTip(button, writer);
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
if (!disabled) {
final CommandMap map = new CommandMap(new Command(facesContext, button));
writer.writeAttribute(DataAttributes.COMMANDS, JsonUtils.encode(map), true);
writer.writeAttribute(HtmlAttributes.HREF, "#", false);
if (label.getAccessKey() != null) {
writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
}
final Integer tabIndex = button.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
}
Style style = new Style(facesContext, button);
writer.writeStyleAttribute(style);
HtmlRendererUtils.renderDojoDndItem(component, writer, true);
writer.writeClassAttribute(Classes.create(button));
if (((UIButton) component).isDefaultCommand()) {
final AbstractUIForm form = ComponentUtils.findAncestor(component, AbstractUIForm.class);
writer.writeAttribute(DataAttributes.DEFAULT, form.getClientId(facesContext), false);
}
writer.flush(); // force closing the start tag
String image = (String) button.getAttributes().get(Attributes.IMAGE);
if (image != null) {
if (ResourceManagerUtils.isAbsoluteResource(image)) {
// absolute Path to image : nothing to do
} else {
image = getImageWithPath(facesContext, image, disabled);
}
writer.startElement(HtmlElements.IMG, null);
writer.writeAttribute(HtmlAttributes.SRC, image, true);
String tip = button.getTip();
writer.writeAttribute(HtmlAttributes.ALT, tip != null ? tip : "", true);
writer.endElement(HtmlElements.IMG);
}
if (label.getText() != null) {
writer.startElement(HtmlElements.SPAN, null);
HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
writer.endElement(HtmlElements.SPAN);
}
writer.endElement(HtmlElements.BUTTON);
if (label.getAccessKey() != null) {
if (LOG.isInfoEnabled()
&& !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
LOG.info("duplicated accessKey : " + label.getAccessKey());
}
HtmlRendererUtils.addClickAcceleratorKey(
facesContext, button.getClientId(facesContext), label.getAccessKey());
}
}