public void encodeEnd(FacesContext facesContext,
UIComponent component) throws IOException {
if (!(component instanceof UICommand)) {
return;
}
UICommand command = (UICommand) component;
String clientId = command.getClientId(facesContext);
CommandRendererHelper helper = new CommandRendererHelper(facesContext, command, CommandRendererHelper.Tag.BUTTON);
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
LabelWithAccessKey label = new LabelWithAccessKey(command);
writer.startElement(HtmlConstants.BUTTON, command);
writer.writeAttribute(HtmlAttributes.TYPE, createButtonType(command), false);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
HtmlRendererUtil.renderTip(command, writer);
writer.writeAttribute(HtmlAttributes.DISABLED, helper.isDisabled());
Integer tabIndex = null;
if (command instanceof UIButtonCommand) {
tabIndex = ((UIButtonCommand) command).getTabIndex();
}
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
if (helper.getOnclick() != null) {
writer.writeAttribute(HtmlAttributes.ONCLICK, helper.getOnclick(), true);
}
writer.writeStyleAttribute();
writer.writeClassAttribute();
writer.flush(); // force closing the start tag
String imageName = (String) command.getAttributes().get(ATTR_IMAGE);
if (imageName != null) {
String image;
if (imageName.startsWith("HTTP:") || imageName.startsWith("FTP:")
|| imageName.startsWith("/")) {
image = imageName;
// absolute Path to image : nothing to do
} else {
image = ResourceManagerUtil.getImageWithPath(facesContext, imageName, helper);
}
writer.startElement(HtmlConstants.IMG, null);
writer.writeAttribute(HtmlAttributes.SRC, image, true);
HtmlRendererUtil.renderImageTip(component, writer);
writer.endElement(HtmlConstants.IMG);
}
if (label.getText() != null) {
if (imageName != null) {
writer.writeText(" "); // separator: e.g.
}
HtmlRendererUtil.writeLabelWithAccessKey(writer, label);
}
writer.endElement(HtmlConstants.BUTTON);
if (label.getAccessKey() != null) {
if (LOG.isInfoEnabled()
&& !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
LOG.info("duplicated accessKey : " + label.getAccessKey());
}
HtmlRendererUtil.addClickAcceleratorKey(
facesContext, command.getClientId(facesContext), label.getAccessKey());
}
if (ComponentUtil.getBooleanAttribute(component, ATTR_DEFAULT_COMMAND)) {
boolean transition = ComponentUtil.getBooleanAttribute(command, ATTR_TRANSITION);
HtmlRendererUtil.setDefaultTransition(facesContext, transition);
HtmlRendererUtil.writeScriptLoader(facesContext, null, new String[]{
"Tobago.setDefaultAction('" + command.getClientId(facesContext) + "')"});
}
}