private static final String ATTR_AJAX_REQUIRED = "_ajaxRequired";
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
CommandButton btn = (CommandButton) component;
String tagName = getTagName(btn);
writer.startElement(tagName, btn);
Rendering.writeIdAttribute(context, component);
Rendering.writeNameAttribute(context, component);
String type = btn.getType();
if (!("submit".equals(type) || "reset".equals(type) || "button".equals(type)))
type = "submit";
if ("input".equals(tagName)) {
String image = btn.getImage();
if (image != null)
type = "image";
writer.writeAttribute("src", Resources.applicationURL(context, image), "image");
}
if ("submit".equals(type) && Environment.isExplorer6()) {
}
writer.writeAttribute("type", type, "type");
if (btn.isDisabled())
writer.writeAttribute("disabled", "disabled", "");
Rendering.writeAttributes(writer, btn,
"accesskey",
"tabindex",
"lang",
"title",
"alt",
"dir");
Object value = btn.getValue();
if (value == null) value = "";
writer.writeAttribute("value", value, "value");
Rendering.writeStyleAndClassAttributes(writer, btn);
if (!btn.isDisabled()) {
boolean ajaxJsRequired = writeEventsWithAjaxSupport(context, writer, btn);
if (ajaxJsRequired)
btn.getAttributes().put(ATTR_AJAX_REQUIRED, Boolean.TRUE);
}
}