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:
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCount()Returns the count of this badge.java.lang.StringgetDisplayValue()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 overcount).count > max— returns"{max}+".count == 0 && !showZero— returns""(badge collapses to nothing). otherwise — returns the decimal string ofcount. Useful for server-side test assertions and for binding the same visual text into another component without re-implementing the rules.intgetMax()Returns the maximum count to display before falling back to "{max}+".java.lang.StringgetPlacement()Returns the placement of the indicator relative to the wrapped child.java.lang.StringgetSeverity()Returns the severity (color theme).java.lang.StringgetValue()Returns the text value of this badge.java.lang.StringgetZclass()booleanisDot()Whether to render as a small red dot, ignoring value and count text.booleanisShowZero()Whether to display when count is zero.protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)voidsetCount(int count)Sets the count of this badge.voidsetDot(boolean dot)Sets whether to render as a small red dot, ignoring value and count text.voidsetMax(int max)Sets the maximum count.voidsetPlacement(java.lang.String placement)Sets the placement.voidsetSeverity(java.lang.String severity)Sets the severity.voidsetShowZero(boolean showZero)Sets whether to display when count is zero.voidsetValue(java.lang.String value)Sets the text value of this badge.-
Methods inherited from class org.zkoss.zul.impl.XulElement
clone, getContext, getCtrlKeys, getPopup, getPropertyAccess, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
-
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
-
-
-
-
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.WrongValueExceptionSets the count of this badge.- Throws:
org.zkoss.zk.ui.WrongValueException- ifcountis 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 overcount).count > max— returns"{max}+".count == 0 && !showZero— returns""(badge collapses to nothing).- otherwise — returns the decimal string of
count.
- 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.WrongValueExceptionSets the maximum count.- Throws:
org.zkoss.zk.ui.WrongValueException- ifmax < 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.WrongValueExceptionSets 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.WrongValueExceptionSets 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:
getZclassin classorg.zkoss.zk.ui.HtmlBasedComponent
-
renderProperties
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws java.io.IOException- Overrides:
renderPropertiesin classXulElement- Throws:
java.io.IOException
-
-