Class Searchbox<E>

  • Type Parameters:
    E - Element type in model
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Disable, Scope, ComponentCtrl

    public class Searchbox<E>
    extends HtmlBasedComponent
    implements 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:
    Serialized Form
    • Constructor Detail

      • Searchbox

        public Searchbox()
    • Method Detail

      • getModel

        public 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​(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:
        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 ItemRenderer<E> getItemRenderer()
        Returns the renderer to render each item, or null if the default renderer is used.
      • setItemRenderer

        public void setItemRenderer​(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​(java.lang.String clsnm)
                             throws java.lang.ReflectiveOperationException
        Sets 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 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​(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.ReflectiveOperationException
        Sets 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()
        Description copied from interface: Disable
        Returns whether it is disabled.

        Default: false.

        Specified by:
        isDisabled in interface Disable
      • setDisabled

        public void setDisabled​(boolean disabled)
        Description copied from interface: Disable
        Sets whether it is disabled.
        Specified by:
        setDisabled in interface 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.
      • isChildable

        protected boolean isChildable()
        Description copied from class: AbstractComponent
        Returns whether this component can have a child.

        Default: return true (means it can have children).

        Overrides:
        isChildable in class AbstractComponent
      • invalidate

        public void invalidate()
        Description copied from interface: Component
        Invalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later. And, the widget associated with this component and all its descendant at the client will be deleted and recreated, too.

        If the application is totally controlled by the server side (i.e., you don't write client codes), you rarely need to access this method.

        It can be called only in the request-processing and event-processing phases. However, it is NOT allowed in the rendering phase.

        Specified by:
        invalidate in interface Component
        Overrides:
        invalidate in class AbstractComponent
      • clone

        public java.lang.Object clone()
        Description copied from interface: Component
        Clones the component. All of its children and descendants are cloned. Also, ID are preserved.
        Specified by:
        clone in interface Component
        Overrides:
        clone in class HtmlBasedComponent
        Returns:
        the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.