Package org.zkoss.zul

Class Badge

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.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:
    10.4.0
    Author:
    yuehfeng
    See Also:
    Serialized Form
    • 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()  
      Badge​(int count)  
      Badge​(java.lang.String value)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getCount()
      Returns the count of this badge.
      java.lang.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.
      int getMax()
      Returns the maximum count to display before falling back to "{max}+".
      java.lang.String getPlacement()
      Returns the placement of the indicator relative to the wrapped child.
      java.lang.String getSeverity()
      Returns the severity (color theme).
      java.lang.String getValue()
      Returns the text value of this badge.
      java.lang.String getZclass()  
      boolean isDot()
      Whether to render as a small red dot, ignoring value and count text.
      boolean isShowZero()
      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​(java.lang.String placement)
      Sets the placement.
      void setSeverity​(java.lang.String severity)
      Sets the severity.
      void setShowZero​(boolean showZero)
      Sets whether to display when count is zero.
      void setValue​(java.lang.String value)
      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, 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, 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, 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, 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 Detail

      • Badge

        public Badge()
      • Badge

        public Badge​(int count)
      • Badge

        public Badge​(java.lang.String value)
    • Method Detail

      • getValue

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

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

      • setValue

        public void setValue​(java.lang.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 java.lang.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:
        10.4.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 java.lang.String getSeverity()
        Returns the severity (color theme).

        Default: "info".

      • setSeverity

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

        public java.lang.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​(java.lang.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 java.lang.String getZclass()
        Overrides:
        getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
      • renderProperties

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