String clientId = uiComponent.getClientId(facesContext);
ResponseWriter writer = facesContext.getResponseWriter();
// commandButton does not need to be nested in a form since JSF 2.0
FormInfo formInfo = findNestingForm(uiComponent, facesContext);
// If we are nested in a form, and we have javascript enabled, and autoscroll is enabled,
// we should write the form submit script
// (define oamSetHiddenInput, oamClearHiddenInput, oamSubmitForm)
// because oamSetHiddenInput is called on onclick function
if (formInfo != null && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext())
&& MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll())
{
HtmlRendererUtils.renderFormSubmitScript(facesContext);
}
writer.startElement(HTML.INPUT_ELEM, uiComponent);
writer.writeAttribute(HTML.ID_ATTR, clientId, org.apache.myfaces.shared_impl.renderkit.JSFAttr.ID_ATTR);
writer.writeAttribute(HTML.NAME_ATTR, clientId, JSFAttr.ID_ATTR);
ExternalContext externalContext = facesContext.getExternalContext();
String image = RendererUtils.getIconSrc(facesContext, uiComponent, JSFAttr.IMAGE_ATTR);
if (image != null)
{
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_IMAGE, org.apache.myfaces.shared_impl.renderkit.JSFAttr.TYPE_ATTR);
writer.writeURIAttribute(HTML.SRC_ATTR, image, org.apache.myfaces.shared_impl.renderkit.JSFAttr.IMAGE_ATTR);
}
else
{
String type = getType(uiComponent);
if (type == null || (!isReset(uiComponent) && !isButton(uiComponent)))
{
type = HTML.INPUT_TYPE_SUBMIT;
}
writer.writeAttribute(HTML.TYPE_ATTR, type, org.apache.myfaces.shared_impl.renderkit.JSFAttr.TYPE_ATTR);
Object value = getValue(uiComponent);
if (value != null)
{
writer.writeAttribute(org.apache.myfaces.shared_impl.renderkit.html.HTML.VALUE_ATTR, value, org.apache.myfaces.shared_impl.renderkit.JSFAttr.VALUE_ATTR);
}
}
Map<String, List<ClientBehavior>> behaviors = null;
if (uiComponent instanceof ClientBehaviorHolder)
{
behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
}
if (JavascriptUtils.isJavascriptAllowed(externalContext) &&
(HtmlRendererUtils.hasClientBehavior(ClientBehaviorEvents.CLICK, behaviors, facesContext) ||
HtmlRendererUtils.hasClientBehavior(ClientBehaviorEvents.ACTION, behaviors, facesContext)))
{
//TODO add the behavior attched rendering here
String onClick = buildBehaviorizedOnClick(uiComponent, behaviors, facesContext, writer, formInfo);
if (onClick.length() != 0) {
writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
}
Map<String, Object> attributes = uiComponent.getAttributes();
HtmlRendererUtils.buildBehaviorChain(
facesContext, uiComponent, behaviors, ClientBehaviorEvents.DBLCLICK,
(String) attributes.get(HTML.ONDBLCLICK_ATTR), "",null);
HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
HTML.BUTTON_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
}
//fallback into the pre 2.0 code to keep backwards comptability with libraries which rely on internals
else if (JavascriptUtils.isJavascriptAllowed(externalContext)) {
StringBuffer onClick = buildOnClick(uiComponent, facesContext, writer);
if (onClick.length() != 0) {
writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
}
HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
HTML.BUTTON_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
} else {
HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
HTML.BUTTON_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
}
HtmlRendererUtils.renderBehaviorizedEventHandlersWithoutOnclick(facesContext, writer, uiComponent, behaviors);
HtmlRendererUtils.renderBehaviorizedFieldEventHandlers(facesContext, writer, uiComponent, behaviors);
if (isDisabled(facesContext, uiComponent))
{
writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, org.apache.myfaces.shared_impl.renderkit.JSFAttr.DISABLED_ATTR);
}
if (isReadonly(facesContext, uiComponent))
{
writer.writeAttribute(HTML.READONLY_ATTR, Boolean.TRUE, org.apache.myfaces.shared_impl.renderkit.JSFAttr.READONLY_ATTR);
}
writer.endElement(HTML.INPUT_ELEM);
if (formInfo != null)
{
HtmlFormRendererBase.renderScrollHiddenInputIfNecessary(formInfo.getForm(), facesContext, writer);
}
// render the UIParameter children of the commandButton (since 2.0)
for (UIComponent child : uiComponent.getChildren())
{