Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public enum Attributes {
iconSize,
id,
immediate,
icon,
image,
inline,
itemDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

public abstract class AbstractUIBadge extends UIOutput implements Visual {

public abstract String getIcon();

public abstract String getImage();

public abstract String getTip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@

package org.apache.myfaces.tobago.internal.component;

import org.apache.myfaces.tobago.component.SupportFieldId;
import org.apache.myfaces.tobago.component.SupportsAccessKey;
import org.apache.myfaces.tobago.component.SupportsAutoSpacing;
import org.apache.myfaces.tobago.component.Visual;
import org.apache.myfaces.tobago.util.ComponentUtils;

import jakarta.faces.component.UICommand;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIInput;
Expand All @@ -33,6 +27,11 @@
import jakarta.faces.component.visit.VisitContext;
import jakarta.faces.component.visit.VisitResult;
import jakarta.faces.context.FacesContext;
import org.apache.myfaces.tobago.component.SupportFieldId;
import org.apache.myfaces.tobago.component.SupportsAccessKey;
import org.apache.myfaces.tobago.component.SupportsAutoSpacing;
import org.apache.myfaces.tobago.component.Visual;
import org.apache.myfaces.tobago.util.ComponentUtils;

/**
* Base class for commands.
Expand All @@ -57,7 +56,9 @@ public boolean isParentOfCommands() {
return parentOfCommands;
}

public abstract java.lang.String getImage();
public abstract String getIcon();

public abstract String getImage();

@Override
public abstract String getLabel();
Expand All @@ -70,6 +71,7 @@ public String getFieldId(final FacesContext facesContext) {
return getClientId(facesContext);
}
}

private static class ParentOfCommandVisitor implements VisitCallback {
private boolean parentOfCommands = false;
private final FacesContext facesContext;
Expand All @@ -85,17 +87,18 @@ public VisitResult visit(VisitContext context, UIComponent target) {
if (!target.getClientId(facesContext).equals(clientId)
&& (target instanceof Visual && !((Visual) target).isPlain()
|| ComponentUtils.isStandardHtmlRendererType(target))) {
if (!(target instanceof AbstractUIEvent)
&& (target instanceof UICommand || target instanceof UIInput)) {
parentOfCommands = true;
return VisitResult.COMPLETE;
} else {
return VisitResult.ACCEPT;
}
if (!(target instanceof AbstractUIEvent)
&& (target instanceof UICommand || target instanceof UIInput)) {
parentOfCommands = true;
return VisitResult.COMPLETE;
} else {
return VisitResult.ACCEPT;
}
} else {
return VisitResult.ACCEPT;
}
}

public boolean isParentOfCommands() {
return parentOfCommands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

package org.apache.myfaces.tobago.internal.component;

import jakarta.faces.context.FacesContext;
import org.apache.myfaces.tobago.component.SupportsAutoSpacing;
import org.apache.myfaces.tobago.util.ComponentUtils;

import jakarta.faces.context.FacesContext;

import java.io.IOException;

/**
Expand All @@ -37,6 +36,8 @@ public abstract class AbstractUISection extends AbstractUICollapsiblePanel imple

public abstract void setLevel(Integer level);

public abstract String getIcon();

public abstract String getImage();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

package org.apache.myfaces.tobago.internal.component;

import org.apache.myfaces.tobago.component.SupportsAccessKey;

import jakarta.faces.component.NamingContainer;
import jakarta.faces.component.behavior.ClientBehaviorHolder;
import org.apache.myfaces.tobago.component.SupportsAccessKey;

/**
* {@link org.apache.myfaces.tobago.internal.taglib.component.TabTagDeclaration}
Expand All @@ -32,6 +31,8 @@ public abstract class AbstractUITab

public abstract String getLabel();

public abstract String getIcon();

public abstract String getImage();

public abstract boolean isDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BadgeRenderer<T extends AbstractUIBadge> extends RendererBase<T> {
public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
final TobagoResponseWriter writer = getResponseWriter(facesContext);
final Markup markup = component.getMarkup() != null ? component.getMarkup() : Markup.NULL;
final String icon = component.getIcon();
final String image = component.getImage();
final String tip = component.getTip();
final String value = getCurrentValue(facesContext, component);
Expand All @@ -54,7 +55,11 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone
if (tip != null) {
writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
}
HtmlRendererUtils.encodeIconOrImage(writer, image);
if (icon != null) {
HtmlRendererUtils.encodeIcon(writer, icon);
} else {
HtmlRendererUtils.encodeIconOrImage(writer, image);
}
if (value != null) {
writer.startElement(HtmlElements.SPAN);
writer.writeText(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone
final String clientId = component.getClientId(facesContext);
final boolean disabled = component.isDisabled();
final LabelWithAccessKey label = new LabelWithAccessKey(component);
final String icon = component.getIcon();
final String image = component.getImage();
final UIComponent labelFacet = ComponentUtils.getFacet(component, Facets.label);
final UIComponent popoverFacet = ComponentUtils.getFacet(component, Facets.popover);
Expand Down Expand Up @@ -157,7 +158,11 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone
insideEnd(facesContext, Facets.popover);
}

HtmlRendererUtils.encodeIconOrImage(writer, image);
if (icon != null) {
HtmlRendererUtils.encodeIcon(writer, icon);
} else {
HtmlRendererUtils.encodeIconOrImage(writer, image);
}

if (labelFacet != null) {
insideBegin(facesContext, Facets.label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone
writer.writeClassAttribute(TobagoClass.HEADER);
writer.startElement(tag);

final String icon = component.getIcon();
final String image = component.getImage();
HtmlRendererUtils.encodeIconOrImage(writer, image);
if (icon != null) {
HtmlRendererUtils.encodeIcon(writer, icon);
} else {
HtmlRendererUtils.encodeIconOrImage(writer, image);
}

final UIComponent labelFacet = ComponentUtils.getFacet(component, Facets.label);
final String labelString = component.getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,14 @@ private void encodeHeader(
}

boolean labelEmpty = true;
final String icon = tab.getIcon();
final String image = tab.getImage();
if (image != null) {
HtmlRendererUtils.encodeIconOrImage(writer, image);
if (icon != null || image != null) {
if (icon != null) {
HtmlRendererUtils.encodeIcon(writer, icon);
} else {
HtmlRendererUtils.encodeIconOrImage(writer, image);
}
labelEmpty = false;
}
if (label.getLabel() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasConverter;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIcon;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasTip;
Expand Down Expand Up @@ -88,5 +89,5 @@
)
})
public interface BadgeTagDeclaration
extends HasIdBindingAndRendered, HasTip, IsVisual, HasConverter, HasValue, HasImage {
extends HasIdBindingAndRendered, HasTip, IsVisual, HasConverter, HasValue, HasIcon, HasImage {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAutoSpacing;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasConfirmation;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasFragment;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIcon;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
Expand Down Expand Up @@ -176,6 +177,6 @@
public interface ButtonTagDeclaration
extends HasIdBindingAndRendered, HasAction, HasActionListener, IsImmediateCommand, HasConfirmation,
HasLink, HasOutcome, HasFragment, IsTransition, HasTarget, IsDisabledBySecurity,
IsOmit, IsVisual, HasLabel, HasAccessKey, HasTip, HasImage,
IsOmit, IsVisual, HasLabel, HasAccessKey, HasTip, HasIcon, HasImage,
IsDefaultCommand, HasTabIndex, HasAutoSpacing {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAutoSpacing;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasConfirmation;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasFragment;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIcon;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
Expand Down Expand Up @@ -133,5 +134,5 @@
public interface LinkTagDeclaration
extends HasIdBindingAndRendered, HasAction, HasActionListener, IsImmediateCommand, HasConfirmation,
HasLink, HasOutcome, HasFragment, IsTransition, HasTarget, IsDisabledBySecurity,
IsOmit, HasImage, HasTabIndex, IsVisual, HasLabel, HasAccessKey, HasTip, HasAutoSpacing {
IsOmit, HasIcon, HasImage, HasTabIndex, IsVisual, HasLabel, HasAccessKey, HasTip, HasAutoSpacing {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAutoSpacing;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasCollapsedMode;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIcon;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
Expand Down Expand Up @@ -56,7 +57,7 @@
})

public interface SectionTagDeclaration
extends HasIdBindingAndRendered, HasLabel, IsVisual, HasImage, IsCollapsed, HasCollapsedMode, HasTip,
extends HasIdBindingAndRendered, HasLabel, IsVisual, HasIcon, HasImage, IsCollapsed, HasCollapsedMode, HasTip,
HasAutoSpacing {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.myfaces.tobago.internal.taglib.component;

import jakarta.faces.component.UIPanel;
import org.apache.myfaces.tobago.apt.annotation.Behavior;
import org.apache.myfaces.tobago.apt.annotation.Facet;
import org.apache.myfaces.tobago.apt.annotation.Tag;
Expand All @@ -27,15 +28,14 @@
import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAccessKey;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIcon;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasTip;
import org.apache.myfaces.tobago.internal.taglib.declaration.IsDisabled;
import org.apache.myfaces.tobago.internal.taglib.declaration.IsVisual;

import jakarta.faces.component.UIPanel;

/**
* Renders a tab within a tab group.
*/
Expand All @@ -56,5 +56,5 @@
isDefault = true)
})
public interface TabTagDeclaration
extends HasIdBindingAndRendered, IsVisual, HasLabel, HasAccessKey, HasTip, IsDisabled, HasImage {
extends HasIdBindingAndRendered, IsVisual, HasLabel, HasAccessKey, HasTip, IsDisabled, HasIcon, HasImage {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.myfaces.tobago.internal.taglib.declaration;

import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;

public interface HasIcon {
/**
* CSS class to render an icon.
*/
@TagAttribute
@UIComponentTagAttribute()
void setIcon(String icon);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@

package org.apache.myfaces.tobago.internal.util;

import jakarta.el.ELContext;
import jakarta.el.ValueExpression;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIInput;
import jakarta.faces.context.FacesContext;
import jakarta.faces.model.SelectItem;
import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.CssItem;
import org.apache.myfaces.tobago.renderkit.css.Icons;
import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
Expand All @@ -32,13 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.el.ELContext;
import jakarta.el.ValueExpression;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIInput;
import jakarta.faces.context.FacesContext;
import jakarta.faces.model.SelectItem;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Locale;
Expand Down Expand Up @@ -74,6 +74,19 @@ public static void writeLabelWithAccessKey(final TobagoResponseWriter writer, fi
}
}

public static void encodeIcon(final TobagoResponseWriter writer, final String icon) throws IOException {
if (icon != null && !icon.isEmpty()) {
writer.startElement(HtmlElements.I);
writer.writeClassAttribute(new CssItem() {
@Override
public String getName() {
return icon;
}
});
writer.endElement(HtmlElements.I);
}
}

public static void encodeIconOrImage(final TobagoResponseWriter writer, final String image) throws IOException {
if (image != null && !image.isEmpty()) {
if (Icons.matches(image)) {
Expand Down Expand Up @@ -179,7 +192,7 @@ public static void writeDataAttributes(
final String value;
if (mapValue instanceof ValueExpression) {
Object expressionValue = ((ValueExpression) mapValue).getValue(elContext);
value = expressionValue !=null ? expressionValue.toString() : null;
value = expressionValue != null ? expressionValue.toString() : null;
} else {
value = mapValue.toString();
}
Expand Down
Loading
Loading