Class Chosenbox

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Scope, ComponentCtrl

    public class Chosenbox
    extends HtmlBasedComponent
    A component that similar to Combobox but handle the multi-selection and the select order.

    Default getZclass(): z-chosenbox. It does not create child widgets for each data, so the memory usage is much lower at the server.

    Since:
    6.0.1
    Author:
    benbai
    See Also:
    Serialized Form
    • Constructor Detail

      • Chosenbox

        public Chosenbox()
    • Method Detail

      • setOpen

        public void setOpen​(boolean open)
      • isOpen

        public boolean isOpen()
      • isDisabled

        public boolean isDisabled()
        Returns whether it is disabled.

        Default: false.

      • setDisabled

        public void setDisabled​(boolean disabled)
        Sets whether it is disabled.
      • getName

        public java.lang.String getName()
        Returns the name of this component.

        Default: null.

        The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.

        Don't use this method if your application is purely based on ZK's event-driven model.

      • setName

        public void setName​(java.lang.String name)
        Sets the name of the input element of this component.

        The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.

        Don't use this method if your application is purely based on ZK's event-driven model.

        Parameters:
        name - the name of this component.
      • getEmptyMessage

        public java.lang.String getEmptyMessage()
        Returns the emptyMessage of the input of this component.

        Default: null.

        The emptyMessage will be displayed in input if nothing selected and not focused.

      • setEmptyMessage

        public void setEmptyMessage​(java.lang.String emptyMessage)
        Sets the emptyMessage of the input of this component.

        The emptyMessage will be displayed in input if nothing selected and not focused.

        Parameters:
        emptyMessage - the emptyMessage of the input of this component.
      • getNoResultsText

        public java.lang.String getNoResultsText()
        Returns the no-result text of this component.

        Default: null.

        The no-result text will be displayed in popup if nothing match to the input value and can not create either, the syntax "{0}" will be replaced with the input value at client side.

      • setNoResultsText

        public void setNoResultsText​(java.lang.String noResultsText)
        Sets the no-result text of this component.

        The no-result text will be displayed in popup if nothing match to the input value and can not create either, the syntax "{0}" will be replaced with the input value at client side.

        Parameters:
        noResultsText - the no-result text of this component.
      • getCreateMessage

        public java.lang.String getCreateMessage()
        Returns the create message of this component.

        Default: null.

        The create message will be displayed in popup if nothing match to the input value but can create as new label, the syntax "{0}" will be replaced with the input value at client side.

      • setCreateMessage

        public void setCreateMessage​(java.lang.String createMessage)
        Sets the create message of this component.

        The create message will be displayed in popup if nothing match to the input value but can create as new label, the syntax "{0}" will be replaced with the input value at client side.

        Parameters:
        createMessage - the create message of this component.
      • getSeparator

        public java.lang.String getSeparator()
        Returns the separate chars of this component.

        Support: 0-9, A-Z (case-insensitive), and ,.;'[]/\-=

        Default: null.

        The separate chars will work as 'Enter' key, it will be not considered as input value but send onSerch or onSearching while key up.

      • setSeparator

        public void setSeparator​(java.lang.String separator)
        Sets the separate chars of this component.

        Support: 0-9, A-Z (case insensitive), and ,.;'[]/\-=

        The separate chars will work as 'Enter' key, it will not considered as input value but send onSerch or onSelect while key up.

      • getSelectedObjects

        public <T> java.util.Set<T> getSelectedObjects()
        Returns the selected objects.
      • setSelectedObjects

        public void setSelectedObjects​(java.util.Collection<?> objects)
        Sets the selected objects.
        Parameters:
        objects - the objects to select.
      • getSelectedIndex

        public int getSelectedIndex()
        Returns the index of the selected item (-1 if no one is selected).
      • setSelectedIndex

        public void setSelectedIndex​(int jsel)
        Sets the index of the selected item (-1 if no one is selected). If model already exists, it will update the selection of model.
        Parameters:
        jsel - the index to select.
      • isCreatable

        public boolean isCreatable()
        Returns whether creates new item.

        Default: false.

        true: will show create message while value of input not exists.

        false: will show no result message while value of input not exists.

      • setCreatable

        public void setCreatable​(boolean creatable)
        Sets whether can create new item.

        Default: false.

        true: will show create message while value of input not exists.

        false: will show no-result text while value of input not exists.

        Parameters:
        creatable - the boolean value.
      • isInplace

        public boolean isInplace()
        Return whether to display Chosenbox's selection as a comma separate label, under inplace="true", when user clicks the label, it turns into a chosenbox.
        Returns:
        whether to display Chosenbox's selection as a comma separate label
        Since:
        8.5.2
      • setInplace

        public void setInplace​(boolean inplace)
        Set whether to display Chosenbox's selection as a comma separate label, under inplace="true", when user clicks the label, it turns into a chosenbox.
        Parameters:
        inplace - to display Chosenbox's selection as a comma separate label
        Since:
        8.5.2
      • getRealRenderer

        public <T> ItemRenderer<T> getRealRenderer()
      • getItemRenderer

        public <T> ItemRenderer<T> getItemRenderer()
        Returns the renderer to render each item, or null if the default renderer is used.
      • getModel

        public <T> ListModel<T> getModel()
        Returns the model associated with this chosenbox, or null if this chosenbox is not associated with any list data model.
      • setModel

        public void setModel​(ListModel<?> model)
        Sets the list model associated with this chosenbox. If a non-null model is assigned, no matter whether it is the same as the previous, it will always cause re-render.
        Parameters:
        model - the list model to associate, or null to dis-associate any previous model.
        Throws:
        UiException - if failed to initialize with the model
      • clearSelection

        public void clearSelection()
        Clear all selected objects.
      • addItemToSelection

        public void addItemToSelection​(java.lang.Object o)
        Add an item into selection.
        Parameters:
        o - the object to add.
      • removeItemFromSelection

        public void removeItemFromSelection​(java.lang.Object o)
        Remove an item from selection.
        Parameters:
        o - the object to remove.
      • 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
      • setItemRenderer

        public void setItemRenderer​(ItemRenderer<?> renderer)
        Sets the renderer which is used to render each item if getModel() is not null.

        Note: changing a render will not cause the chosenbox to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(getModel())), or fire an ListDataEvent event.

        Parameters:
        renderer - the renderer, or null to use the default.
        Throws:
        UiException - if failed to initialize with the model
      • setItemRenderer

        public void setItemRenderer​(java.lang.String clsnm)
                             throws java.lang.ClassNotFoundException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.lang.reflect.InvocationTargetException
        Sets the renderer by use of a class name. It creates an instance automatically.
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.IllegalAccessException
        java.lang.InstantiationException
        java.lang.reflect.InvocationTargetException
      • onInitRender

        public void onInitRender()
      • onInitSelection

        public void onInitSelection()
      • 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.