Package org.zkoss.zkmax.zul
Class Searchbox<E>
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zk.ui.HtmlBasedComponent
-
- org.zkoss.zkmax.zul.Searchbox<E>
-
- Type Parameters:
E- Element type in model
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.zkoss.zk.ui.Component,org.zkoss.zk.ui.ext.Disable,org.zkoss.zk.ui.ext.Scope,org.zkoss.zk.ui.sys.ComponentCtrl
public class Searchbox<E> extends org.zkoss.zk.ui.HtmlBasedComponent implements org.zkoss.zk.ui.ext.DisableA dropdown list that allows users to search and select items.Available in ZK EE.
Default
getZclass(): z-searchbox.Events: onOpen, onSelect, onSearching, onAfterRender
Besides assign a list model, you could assign a renderer (a
ItemRendererinstance) to a searchbox, such that the searchbox will use this renderer to render the data returned byListModel.getElementAt(int). If not assigned, the default renderer, which assumes a label per item, is used.- Since:
- 9.0.0
- Author:
- rudyhuang
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Searchbox()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearSelection()Clears the selection.java.lang.Objectclone()org.zkoss.util.Converter<java.util.Collection<E>,java.lang.String>getItemConverter()Returns the converter that generates the label text shown in the searchbox from selected items, or null to use the default implementation.org.zkoss.zul.ItemRenderer<E>getItemRenderer()Returns the renderer to render each item, or null if the default renderer is used.org.zkoss.zul.ListModel<E>getModel()Returns the model associated with this searchbox, or null if this searchbox is not associated with any list data model.java.lang.StringgetPlaceholder()Returns the placeholder text.java.lang.StringgetSearchMessage()Returns the placeholder message of the search text field, or null to use the default message.java.lang.StringgetSearchText()Returns the value of the search textintgetSelectedCount()Returns the number of items being selected.EgetSelectedItem()Returns the selected item, or null if no item is selected.java.util.Set<E>getSelectedItems()Returns all selected items.java.lang.StringgetZclass()voidinvalidate()booleanisAutoclose()Returns whether to automatically close the list if a user is selected any item.protected booleanisChildable()booleanisDisabled()booleanisMultiple()Returns whether multiple selections are allowed.booleanisOpen()Returns whether this searchbox is open.voidonInitRender()Handles a private event, onInitRender.voidonPageAttached(org.zkoss.zk.ui.Page newpage, org.zkoss.zk.ui.Page oldpage)voidonPageDetached(org.zkoss.zk.ui.Page page)protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)voidservice(org.zkoss.zk.au.AuRequest request, boolean everError)voidsessionDidActivate(org.zkoss.zk.ui.Page page)voidsessionWillPassivate(org.zkoss.zk.ui.Page page)voidsetAutoclose(boolean autoclose)Sets whether to automatically close the list if a user is selected any item.voidsetDisabled(boolean disabled)voidsetItemConverter(java.lang.String clsnm)Sets the converter by use of a class name.voidsetItemConverter(org.zkoss.util.Converter<java.util.Collection<E>,java.lang.String> converter)Sets the converter that generates the label text shown in the searchbox from selected items.voidsetItemRenderer(java.lang.String clsnm)Sets the renderer by use of a class name.voidsetItemRenderer(org.zkoss.zul.ItemRenderer<E> renderer)Sets the renderer which is used to render each item ifgetModel()is not null.voidsetModel(org.zkoss.zul.ListModel<E> model)Sets the list model associated with this searchbox.voidsetMultiple(boolean multiple)Sets whether multiple selections are allowed.voidsetOpen(boolean open)Drops down or closes the list of items.voidsetPlaceholder(java.lang.String placeholder)Sets the placeholder text that is displayed when the selected item is empty.voidsetSearchMessage(java.lang.String searchMessage)Sets the placeholder message of the search text field.voidsetSearchText(java.lang.String searchText)Sets the value of the search text.voidsetSelectedItem(E item)Deselects all of the currently selected items and selects the given item.voidsetSelectedItems(java.util.Collection<E> selectedItems)Selects the given items.-
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getPropertyAccess, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, 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, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, 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, 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
-
getModel
public org.zkoss.zul.ListModel<E> getModel()
Returns the model associated with this searchbox, or null if this searchbox is not associated with any list data model.
-
setModel
public void setModel(org.zkoss.zul.ListModel<E> model)
Sets the list model associated with this searchbox.- Parameters:
model- the list model to associate, or null to dis-associate any previous model. If not null, it must implementSelectable.- Throws:
org.zkoss.zk.ui.UiException- if failed to initialize with the model
-
onInitRender
public void onInitRender()
Handles a private event, onInitRender. It is used only for implementation, and you rarely need to invoke it explicitly.
-
getItemRenderer
public org.zkoss.zul.ItemRenderer<E> getItemRenderer()
Returns the renderer to render each item, or null if the default renderer is used.
-
setItemRenderer
public void setItemRenderer(org.zkoss.zul.ItemRenderer<E> renderer)
Sets the renderer which is used to render each item ifgetModel()is not null.Note: changing a render will cause the searchbox to re-render.
- Parameters:
renderer- the renderer, or null to use the default.
-
setItemRenderer
public void setItemRenderer(java.lang.String clsnm) throws java.lang.ReflectiveOperationExceptionSets the renderer by use of a class name. It creates an instance automatically.- Parameters:
clsnm- The class name- Throws:
java.lang.ReflectiveOperationException- if failed to initialize the renderer
-
getItemConverter
public org.zkoss.util.Converter<java.util.Collection<E>,java.lang.String> getItemConverter()
Returns the converter that generates the label text shown in the searchbox from selected items, or null to use the default implementation. (joining by commas, i.g. "A, B, C")
-
setItemConverter
public void setItemConverter(org.zkoss.util.Converter<java.util.Collection<E>,java.lang.String> converter)
Sets the converter that generates the label text shown in the searchbox from selected items.- Parameters:
converter- the converter, or null to use the default implementation.
-
setItemConverter
public void setItemConverter(java.lang.String clsnm) throws java.lang.ReflectiveOperationExceptionSets the converter by use of a class name. It creates an instance automatically.- Parameters:
clsnm- The class name- Throws:
java.lang.ReflectiveOperationException- if failed to initialize the converter
-
getSearchMessage
public java.lang.String getSearchMessage()
Returns the placeholder message of the search text field, or null to use the default message.
-
setSearchMessage
public void setSearchMessage(java.lang.String searchMessage)
Sets the placeholder message of the search text field.
-
getPlaceholder
public java.lang.String getPlaceholder()
Returns the placeholder text.
-
setPlaceholder
public void setPlaceholder(java.lang.String placeholder)
Sets the placeholder text that is displayed when the selected item is empty.
-
isMultiple
public boolean isMultiple()
Returns whether multiple selections are allowed.Default: false.
-
setMultiple
public void setMultiple(boolean multiple)
Sets whether multiple selections are allowed.Notice that, if a model is assigned, it will change the model's state (by
Selectable.setMultiple(boolean)).
-
isOpen
public boolean isOpen()
Returns whether this searchbox is open.Default: false.
-
setOpen
public void setOpen(boolean open)
Drops down or closes the list of items.
-
isDisabled
public boolean isDisabled()
- Specified by:
isDisabledin interfaceorg.zkoss.zk.ui.ext.Disable
-
setDisabled
public void setDisabled(boolean disabled)
- Specified by:
setDisabledin interfaceorg.zkoss.zk.ui.ext.Disable
-
isAutoclose
public boolean isAutoclose()
Returns whether to automatically close the list if a user is selected any item.Default: false
-
setAutoclose
public void setAutoclose(boolean autoclose)
Sets whether to automatically close the list if a user is selected any item.
-
getSelectedItems
public java.util.Set<E> getSelectedItems()
Returns all selected items.
-
setSelectedItems
public void setSelectedItems(java.util.Collection<E> selectedItems)
Selects the given items. Must be non-null values.
-
getSelectedItem
public E getSelectedItem()
Returns the selected item, or null if no item is selected.
-
setSelectedItem
public void setSelectedItem(E item)
Deselects all of the currently selected items and selects the given item.
-
getSelectedCount
public int getSelectedCount()
Returns the number of items being selected.
-
clearSelection
public void clearSelection()
Clears the selection.
-
getSearchText
public java.lang.String getSearchText()
Returns the value of the search text- Since:
- 10.2.0
-
setSearchText
public void setSearchText(java.lang.String searchText)
Sets the value of the search text.- Since:
- 10.2.0
-
renderProperties
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws java.io.IOException- Overrides:
renderPropertiesin classorg.zkoss.zk.ui.HtmlBasedComponent- Throws:
java.io.IOException
-
service
public void service(org.zkoss.zk.au.AuRequest request, boolean everError)- Specified by:
servicein interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
servicein classorg.zkoss.zk.ui.HtmlBasedComponent
-
getZclass
public java.lang.String getZclass()
- Overrides:
getZclassin classorg.zkoss.zk.ui.HtmlBasedComponent
-
isChildable
protected boolean isChildable()
- Overrides:
isChildablein classorg.zkoss.zk.ui.AbstractComponent
-
onPageAttached
public void onPageAttached(org.zkoss.zk.ui.Page newpage, org.zkoss.zk.ui.Page oldpage)- Specified by:
onPageAttachedin interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
onPageAttachedin classorg.zkoss.zk.ui.AbstractComponent
-
onPageDetached
public void onPageDetached(org.zkoss.zk.ui.Page page)
- Specified by:
onPageDetachedin interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
onPageDetachedin classorg.zkoss.zk.ui.AbstractComponent
-
invalidate
public void invalidate()
- Specified by:
invalidatein interfaceorg.zkoss.zk.ui.Component- Overrides:
invalidatein classorg.zkoss.zk.ui.AbstractComponent
-
clone
public java.lang.Object clone()
- Specified by:
clonein interfaceorg.zkoss.zk.ui.Component- Overrides:
clonein classorg.zkoss.zk.ui.HtmlBasedComponent
-
sessionWillPassivate
public void sessionWillPassivate(org.zkoss.zk.ui.Page page)
- Specified by:
sessionWillPassivatein interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
sessionWillPassivatein classorg.zkoss.zk.ui.AbstractComponent
-
sessionDidActivate
public void sessionDidActivate(org.zkoss.zk.ui.Page page)
- Specified by:
sessionDidActivatein interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
sessionDidActivatein classorg.zkoss.zk.ui.AbstractComponent
-
-