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
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.ExtraCtrlNested 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
_zclassFields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPEFields 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 -
Method Summary
Modifier and TypeMethodDescriptionintgetCount()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 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}+".Returns the placement of the indicator relative to the wrapped child.Returns the severity (color theme).getValue()Returns the text value of this badge.booleanisDot()Whether to render as a small red dot, ignoring value and count text.booleanWhether 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(String placement) Sets the placement.voidsetSeverity(String severity) Sets the severity.voidsetShowZero(boolean showZero) Sets whether to display when count is zero.voidSets 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, setTooltipAttributesMethods 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, setZIndexDirectlyMethods 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
-
Constructor Details
-
Badge
public Badge() -
Badge
public Badge(int count) -
Badge
-
-
Method Details
-
getValue
Returns the text value of this badge.Default: null. When non-null, takes precedence over
getCount(). -
setValue
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- ifcountis negative — a badge is a counter, not a signed value.
-
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:
- 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- 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
Returns the severity (color theme).Default: "info".
-
setSeverity
Sets the severity.- Parameters:
severity- "info", "success", "warning", "error" or "neutral".- Throws:
org.zkoss.zk.ui.WrongValueException
-
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
Sets the placement.- Parameters:
placement- "top_right", "top_left", "bottom_right" or "bottom_left".- Throws:
org.zkoss.zk.ui.WrongValueException
-
getZclass
- Overrides:
getZclassin classorg.zkoss.zk.ui.HtmlBasedComponent
-
renderProperties
- Overrides:
renderPropertiesin classXulElement- Throws:
IOException
-