Package org.zkoss.zul

Class Badge

java.lang.Object
org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zul.impl.XulElement
org.zkoss.zul.Badge
All Implemented Interfaces:
Serializable, Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl

public class Badge extends XulElement
A badge (count or status indicator). May be used standalone for pure visual display, or wrap around a child component to pin an indicator onto the child (e.g., a Button with "3 new" in the top-right corner).

Default getZclass(): "z-badge".

Since:
11.0.0
Author:
yuehfeng
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrl

    Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

    org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo
  • Field Summary

    Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    _zclass

    Fields inherited from interface org.zkoss.zk.ui.Component

    APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE

    Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

    AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Badge(int count)
     
    Badge(String value)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the count of this badge.
    Returns the string that will actually be rendered inside the badge, resolved from the current property set: dot=true — returns "" (dot mode shows no text). value != null — returns the value verbatim (takes precedence over count). count > max — returns "{max}+". count == 0 && !showZero — returns "" (badge collapses to nothing). otherwise — returns the decimal string of count. Useful for server-side test assertions and for binding the same visual text into another component without re-implementing the rules.
    int
    Returns the maximum count to display before falling back to "{max}+".
    Returns the placement of the indicator relative to the wrapped child.
    Returns the severity (color theme).
    Returns the text value of this badge.
     
    boolean
    Whether to render as a small red dot, ignoring value and count text.
    boolean
    Whether to display when count is zero.
    protected void
    renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
     
    void
    setCount(int count)
    Sets the count of this badge.
    void
    setDot(boolean dot)
    Sets whether to render as a small red dot, ignoring value and count text.
    void
    setMax(int max)
    Sets the maximum count.
    void
    setPlacement(String placement)
    Sets the placement.
    void
    setSeverity(String severity)
    Sets the severity.
    void
    setShowZero(boolean showZero)
    Sets whether to display when count is zero.
    void
    Sets the text value of this badge.

    Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, service, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setSkeleton, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly

    Methods inherited from class org.zkoss.zk.ui.AbstractComponent

    addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isChildable, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Badge

      public Badge()
    • Badge

      public Badge(int count)
    • Badge

      public Badge(String value)
  • Method Details

    • getValue

      public String getValue()
      Returns the text value of this badge.

      Default: null. When non-null, takes precedence over getCount().

    • setValue

      public void setValue(String value)
      Sets the text value of this badge.
    • getCount

      public int getCount()
      Returns the count of this badge.

      Default: 0.

    • setCount

      public void setCount(int count) throws org.zkoss.zk.ui.WrongValueException
      Sets the count of this badge.
      Throws:
      org.zkoss.zk.ui.WrongValueException - if count is negative — a badge is a counter, not a signed value.
    • getDisplayValue

      public String getDisplayValue()
      Returns the string that will actually be rendered inside the badge, resolved from the current property set:
      • dot=true — returns "" (dot mode shows no text).
      • value != null — returns the value verbatim (takes precedence over count).
      • count > max — returns "{max}+".
      • count == 0 && !showZero — returns "" (badge collapses to nothing).
      • otherwise — returns the decimal string of count.
      Useful for server-side test assertions and for binding the same visual text into another component without re-implementing the rules.
      Since:
      11.0.0
    • getMax

      public int getMax()
      Returns the maximum count to display before falling back to "{max}+".

      Default: 99.

    • setMax

      public void setMax(int max) throws org.zkoss.zk.ui.WrongValueException
      Sets the maximum count.
      Throws:
      org.zkoss.zk.ui.WrongValueException - if max < 1 — the cap must be at least 1 for the "{max}+" overflow indicator to make sense.
    • isShowZero

      public boolean isShowZero()
      Whether to display when count is zero.

      Default: false.

    • setShowZero

      public void setShowZero(boolean showZero)
      Sets whether to display when count is zero.
      Parameters:
      showZero - whether the badge shows when the count is zero; default false. Calls smartUpdate when changed.
    • isDot

      public boolean isDot()
      Whether to render as a small red dot, ignoring value and count text.

      Default: false.

    • setDot

      public void setDot(boolean dot)
      Sets whether to render as a small red dot, ignoring value and count text.
      Parameters:
      dot - whether to render as a dot instead of value/count text; default false. Calls smartUpdate when changed.
    • getSeverity

      public String getSeverity()
      Returns the severity (color theme).

      Default: "info".

    • setSeverity

      public void setSeverity(String severity) throws org.zkoss.zk.ui.WrongValueException
      Sets the severity.
      Parameters:
      severity - "info", "success", "warning", "error" or "neutral".
      Throws:
      org.zkoss.zk.ui.WrongValueException
    • getPlacement

      public String getPlacement()
      Returns the placement of the indicator relative to the wrapped child.

      Default: "top_right". Only effective in wrap mode (when the badge has children).

    • setPlacement

      public void setPlacement(String placement) throws org.zkoss.zk.ui.WrongValueException
      Sets the placement.
      Parameters:
      placement - "top_right", "top_left", "bottom_right" or "bottom_left".
      Throws:
      org.zkoss.zk.ui.WrongValueException
    • getZclass

      public String getZclass()
      Overrides:
      getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
    • renderProperties

      protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws IOException
      Overrides:
      renderProperties in class XulElement
      Throws:
      IOException