Package org.zkoss.zul

Class Badge

All Implemented Interfaces:
Serializable, Cloneable, Component, Scope, 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:
  • 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 WrongValueException
      Sets the count of this badge.
      Throws:
      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 WrongValueException
      Sets the maximum count.
      Throws:
      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 WrongValueException
      Sets the severity.
      Parameters:
      severity - "info", "success", "warning", "error" or "neutral".
      Throws:
      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 WrongValueException
      Sets the placement.
      Parameters:
      placement - "top_right", "top_left", "bottom_right" or "bottom_left".
      Throws:
      WrongValueException
    • getZclass

      public String getZclass()
      Description copied from class: HtmlBasedComponent
      Returns the ZK Cascading Style class for this component. It usually depends on the implementation of the mold (AbstractComponent.getMold()).

      Default: null (the default value depends on element).

      HtmlBasedComponent.setZclass(java.lang.String)) will completely replace the default style of a component. In other words, the default style of a component is associated with the default value of HtmlBasedComponent.getZclass(). Once it is changed, the default style won't be applied at all. If you want to perform small adjustments, use HtmlBasedComponent.setSclass(java.lang.String) instead.

      Overrides:
      getZclass in class HtmlBasedComponent
      See Also:
    • renderProperties

      protected void renderProperties(ContentRenderer renderer) throws IOException
      Description copied from class: HtmlBasedComponent
      Renders the content of this component, excluding the enclosing tags and children.

      See also ZK Client-side Reference: Property Rendering

      Overrides:
      renderProperties in class XulElement
      Throws:
      IOException