in tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java [70:180]
public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
final String clientId = component.getClientId(facesContext);
final boolean disabled = component.isDisabled();
final LabelWithAccessKey label = new LabelWithAccessKey(component);
final String image = component.getImage();
final UIComponent labelFacet = ComponentUtils.getFacet(component, Facets.label);
final UIComponent popoverFacet = ComponentUtils.getFacet(component, Facets.popover);
final boolean anchor = (component.getLink() != null || component.getOutcome() != null) && !disabled;
final String target = component.getTarget();
final boolean autoSpacing = component.getAutoSpacing(facesContext);
final boolean parentOfCommands = component.isParentOfCommands();
final boolean dropdownSubmenu = isInside(facesContext, HtmlElements.COMMAND);
final Markup markup = component.getMarkup() != null ? component.getMarkup() : Markup.NULL;
final TobagoResponseWriter writer = getResponseWriter(facesContext);
encodeBeginOuter(facesContext, component);
if (anchor) {
writer.startElement(HtmlElements.A, component);
} else {
writer.startElement(HtmlElements.BUTTON, component);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlButtonTypes.BUTTON);
}
writer.writeIdAttribute(component.getFieldId(facesContext));
writer.writeNameAttribute(clientId);
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
if (!disabled) {
if (anchor) {
final String href = RenderUtils.generateUrl(facesContext, component);
writer.writeAttribute(HtmlAttributes.HREF, href, true);
writer.writeAttribute(HtmlAttributes.TARGET, target, true);
component.setOmit(true);
}
if (label.getAccessKey() != null) {
writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(label.getAccessKey()), false);
AccessKeyLogger.addAccessKey(facesContext, label.getAccessKey(), clientId);
}
final int tabIndex = ComponentUtils.getIntAttribute(component, Attributes.tabIndex);
if (tabIndex != 0) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
}
HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
if (parentOfCommands) {
writer.writeAttribute(Arias.EXPANDED, Boolean.FALSE.toString(), false);
}
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, component);
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
writer.writeClassAttribute(
getRendererCssClass(),
getCssItems(facesContext, component),
autoSpacing && !dropdownSubmenu ? TobagoClass.AUTO__SPACING : null,
dropdownSubmenu ? BootstrapClass.DROPDOWN_ITEM : null,
parentOfCommands && !dropdownSubmenu ? BootstrapClass.DROPDOWN_TOGGLE : null,
markup.contains(Markup.HIDE_TOGGLE_ICON) ? TobagoClass.HIDE_TOGGLE_ICON : null,
label.getLabel() == null && image == null && labelFacet == null ? BootstrapClass.DROPDOWN_TOGGLE_SPLIT : null,
component.getCustomClass(),
isInside(facesContext, HtmlElements.TOBAGO_LINKS) && !dropdownSubmenu ? BootstrapClass.NAV_LINK : null);
final boolean defaultCommand = ComponentUtils.getBooleanAttribute(component, Attributes.defaultCommand);
if (defaultCommand) {
final AbstractUIFormBase form = ComponentUtils.findAncestor(component, AbstractUIFormBase.class);
if (form != null) {
writer.writeAttribute(DataAttributes.DEFAULT, form.getClientId(facesContext), false);
} else {
LOG.warn("No form found for {}", clientId);
}
}
if (!disabled) {
encodeBehavior(writer, facesContext, component);
}
if (popoverFacet != null) {
insideBegin(facesContext, Facets.popover);
for (final UIComponent child : RenderUtils.getFacetChildren(popoverFacet)) {
child.encodeAll(facesContext);
}
insideEnd(facesContext, Facets.popover);
}
HtmlRendererUtils.encodeIconOrImage(writer, image);
if (labelFacet != null) {
insideBegin(facesContext, Facets.label);
for (final UIComponent child : RenderUtils.getFacetChildren(labelFacet)) {
child.encodeAll(facesContext);
}
insideEnd(facesContext, Facets.label);
} else if (label.getLabel() != null) {
writer.startElement(HtmlElements.SPAN);
HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
writer.endElement(HtmlElements.SPAN);
encodeBadge(facesContext, component);
}
if (anchor) {
writer.endElement(HtmlElements.A);
} else {
writer.endElement(HtmlElements.BUTTON);
}
}