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:
Serializable, 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.Disable
A 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 ItemRenderer instance) to a searchbox, such that the searchbox will use this renderer to render the data returned by ListModel.getElementAt(int). If not assigned, the default renderer, which assumes a label per item, is used.

Since:
9.0.0
Author:
rudyhuang
See Also:
  • 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the selection.
     
    org.zkoss.util.Converter<Collection<E>,String>
    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>
    Returns the renderer to render each item, or null if the default renderer is used.
    org.zkoss.zul.ListModel<E>
    Returns the model associated with this searchbox, or null if this searchbox is not associated with any list data model.
    Returns the placeholder text.
    Returns the placeholder message of the search text field, or null to use the default message.
    Returns the value of the search text
    int
    Returns the number of items being selected.
    Returns the selected item, or null if no item is selected.
    Returns all selected items.
     
    void
     
    boolean
    Returns whether to automatically close the list if a user is selected any item.
    protected boolean
     
    boolean
     
    boolean
    Returns whether multiple selections are allowed.
    boolean
    Returns whether this searchbox is open.
    void
    Handles a private event, onInitRender.
    void
    onPageAttached(org.zkoss.zk.ui.Page newpage, org.zkoss.zk.ui.Page oldpage)
     
    void
    onPageDetached(org.zkoss.zk.ui.Page page)
     
    protected void
    renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
     
    void
    service(org.zkoss.zk.au.AuRequest request, boolean everError)
     
    void
    sessionDidActivate(org.zkoss.zk.ui.Page page)
     
    void
    sessionWillPassivate(org.zkoss.zk.ui.Page page)
     
    void
    setAutoclose(boolean autoclose)
    Sets whether to automatically close the list if a user is selected any item.
    void
    setDisabled(boolean disabled)
     
    void
    Sets the converter by use of a class name.
    void
    setItemConverter(org.zkoss.util.Converter<Collection<E>,String> converter)
    Sets the converter that generates the label text shown in the searchbox from selected items.
    void
    Sets the renderer by use of a class name.
    void
    setItemRenderer(org.zkoss.zul.ItemRenderer<E> renderer)
    Sets the renderer which is used to render each item if getModel() is not null.
    void
    setModel(org.zkoss.zul.ListModel<E> model)
    Sets the list model associated with this searchbox.
    void
    setMultiple(boolean multiple)
    Sets whether multiple selections are allowed.
    void
    setOpen(boolean open)
    Drops down or closes the list of items.
    void
    setPlaceholder(String placeholder)
    Sets the placeholder text that is displayed when the selected item is empty.
    void
    setSearchMessage(String searchMessage)
    Sets the placeholder message of the search text field.
    void
    setSearchText(String searchText)
    Sets the value of the search text.
    void
    Deselects all of the currently selected items and selects the given item.
    void
    setSelectedItems(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, getSkeleton, 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, setSkeleton, 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, getStubonlyDescendants, 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, 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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Searchbox

      public Searchbox()
  • Method Details

    • 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 implement Selectable.
      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 if getModel() 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(String clsnm) throws ReflectiveOperationException
      Sets the renderer by use of a class name. It creates an instance automatically.
      Parameters:
      clsnm - The class name
      Throws:
      ReflectiveOperationException - if failed to initialize the renderer
    • getItemConverter

      public org.zkoss.util.Converter<Collection<E>,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<Collection<E>,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(String clsnm) throws ReflectiveOperationException
      Sets the converter by use of a class name. It creates an instance automatically.
      Parameters:
      clsnm - The class name
      Throws:
      ReflectiveOperationException - if failed to initialize the converter
    • getSearchMessage

      public String getSearchMessage()
      Returns the placeholder message of the search text field, or null to use the default message.
    • setSearchMessage

      public void setSearchMessage(String searchMessage)
      Sets the placeholder message of the search text field.
    • getPlaceholder

      public String getPlaceholder()
      Returns the placeholder text.
    • setPlaceholder

      public void setPlaceholder(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:
      isDisabled in interface org.zkoss.zk.ui.ext.Disable
    • setDisabled

      public void setDisabled(boolean disabled)
      Specified by:
      setDisabled in interface org.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 Set<E> getSelectedItems()
      Returns all selected items.
    • setSelectedItems

      public void setSelectedItems(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 String getSearchText()
      Returns the value of the search text
      Since:
      10.2.0
    • setSearchText

      public void setSearchText(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 IOException
      Overrides:
      renderProperties in class org.zkoss.zk.ui.HtmlBasedComponent
      Throws:
      IOException
    • service

      public void service(org.zkoss.zk.au.AuRequest request, boolean everError)
      Specified by:
      service in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      service in class org.zkoss.zk.ui.HtmlBasedComponent
    • getZclass

      public String getZclass()
      Overrides:
      getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
    • isChildable

      protected boolean isChildable()
      Overrides:
      isChildable in class org.zkoss.zk.ui.AbstractComponent
    • onPageAttached

      public void onPageAttached(org.zkoss.zk.ui.Page newpage, org.zkoss.zk.ui.Page oldpage)
      Specified by:
      onPageAttached in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      onPageAttached in class org.zkoss.zk.ui.AbstractComponent
    • onPageDetached

      public void onPageDetached(org.zkoss.zk.ui.Page page)
      Specified by:
      onPageDetached in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      onPageDetached in class org.zkoss.zk.ui.AbstractComponent
    • invalidate

      public void invalidate()
      Specified by:
      invalidate in interface org.zkoss.zk.ui.Component
      Overrides:
      invalidate in class org.zkoss.zk.ui.AbstractComponent
    • clone

      public Object clone()
      Specified by:
      clone in interface org.zkoss.zk.ui.Component
      Overrides:
      clone in class org.zkoss.zk.ui.HtmlBasedComponent
    • sessionWillPassivate

      public void sessionWillPassivate(org.zkoss.zk.ui.Page page)
      Specified by:
      sessionWillPassivate in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      sessionWillPassivate in class org.zkoss.zk.ui.AbstractComponent
    • sessionDidActivate

      public void sessionDidActivate(org.zkoss.zk.ui.Page page)
      Specified by:
      sessionDidActivate in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      sessionDidActivate in class org.zkoss.zk.ui.AbstractComponent