private static final Logger LOG = LoggerFactory.getLogger(ButtonRenderer.class);
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
UIButton button = (UIButton) component;
String clientId = button.getClientId(facesContext);
CommandRendererHelper helper = new CommandRendererHelper(facesContext, button, CommandRendererHelper.Tag.BUTTON);
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
LabelWithAccessKey label = new LabelWithAccessKey(button);
writer.startElement(HtmlElements.BUTTON, button);
writer.writeAttribute(HtmlAttributes.TYPE, createButtonType(button), false);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, button);
HtmlRendererUtils.renderTip(button, writer);
writer.writeAttribute(HtmlAttributes.DISABLED, helper.isDisabled());
Integer tabIndex = button.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
if (helper.getOnclick() != null) {
writer.writeAttribute(HtmlAttributes.ONCLICK, helper.getOnclick(), true);
}
Style style = new Style(facesContext, button);
writer.writeStyleAttribute(style);
HtmlRendererUtils.renderDojoDndItem(component, writer, true);
writer.writeClassAttribute(Classes.create(button));
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, helper.isDisabled());
}
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());
}
if (ComponentUtils.getBooleanAttribute(component, Attributes.DEFAULT_COMMAND)) {
boolean transition = ComponentUtils.getBooleanAttribute(button, Attributes.TRANSITION);
HtmlRendererUtils.setDefaultTransition(facesContext, transition);
HtmlRendererUtils.writeScriptLoader(facesContext, null, new String[]{
"Tobago.setDefaultAction('" + button.getClientId(facesContext) + "')"});
}
}