Class Chosenbox

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl

    public class Chosenbox
    extends org.zkoss.zk.ui.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
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  Chosenbox.ExtraCtrl
      A utility class to implement HtmlBasedComponent.getExtraCtrl().
      • 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 
      Modifier and Type Field Description
      static java.lang.String ATTR_FILTER_LOGIC  
      static java.lang.String ATTR_FILTER_LOGIC_CONTAINS  
      static java.lang.String ATTR_FILTER_LOGIC_STARTS_WITH  
      • 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
      Chosenbox()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addItemToSelection​(java.lang.Object o)
      Add an item into selection.
      void clearSelection()
      Clear all selected objects.
      java.lang.Object clone()  
      java.lang.String getCreateMessage()
      Returns the create message of this component.
      java.lang.String getEmptyMessage()
      Returns the emptyMessage of the input of this component.
      java.lang.Object getExtraCtrl()  
      <T> org.zkoss.zul.ItemRenderer<T> getItemRenderer()
      Returns the renderer to render each item, or null if the default renderer is used.
      <T> org.zkoss.zul.ListModel<T> getModel()
      Returns the model associated with this chosenbox, or null if this chosenbox is not associated with any list data model.
      java.lang.String getName()
      Returns the name of this component.
      java.lang.String getNoResultsText()
      Returns the no-result text of this component.
      <T> org.zkoss.zul.ItemRenderer<T> getRealRenderer()  
      int getSelectedIndex()
      Returns the index of the selected item (-1 if no one is selected).
      <T> java.util.Set<T> getSelectedObjects()
      Returns the selected objects.
      java.lang.String getSeparator()
      Returns the separate chars of this component.
      java.lang.String getZclass()  
      void invalidate()  
      protected boolean isChildable()  
      boolean isCreatable()
      Returns whether creates new item.
      boolean isDisabled()
      Returns whether it is disabled.
      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.
      boolean isOpen()  
      void onInitRender()  
      void onInitSelection()  
      void onPageAttached​(org.zkoss.zk.ui.Page newpage, org.zkoss.zk.ui.Page oldpage)  
      void onPageDetached​(org.zkoss.zk.ui.Page page)  
      void removeItemFromSelection​(java.lang.Object o)
      Remove an item from selection.
      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 setCreatable​(boolean creatable)
      Sets whether can create new item.
      void setCreateMessage​(java.lang.String createMessage)
      Sets the create message of this component.
      void setDisabled​(boolean disabled)
      Sets whether it is disabled.
      void setEmptyMessage​(java.lang.String emptyMessage)
      Sets the emptyMessage of the input of this component.
      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.
      void setItemRenderer​(java.lang.String clsnm)
      Sets the renderer by use of a class name.
      void setItemRenderer​(org.zkoss.zul.ItemRenderer<?> renderer)
      Sets the renderer which is used to render each item if getModel() is not null.
      void setModel​(org.zkoss.zul.ListModel<?> model)
      Sets the list model associated with this chosenbox.
      void setName​(java.lang.String name)
      Sets the name of the input element of this component.
      void setNoResultsText​(java.lang.String noResultsText)
      Sets the no-result text of this component.
      void setOpen​(boolean open)  
      void setSelectedIndex​(int jsel)
      Sets the index of the selected item (-1 if no one is selected).
      void setSelectedObjects​(java.util.Collection<?> objects)
      Sets the selected objects.
      void setSeparator​(java.lang.String separator)
      Sets the separate chars of this component.
      • Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, 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
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ATTR_FILTER_LOGIC

        public static final java.lang.String ATTR_FILTER_LOGIC
        See Also:
        Constant Field Values
      • ATTR_FILTER_LOGIC_CONTAINS

        public static final java.lang.String ATTR_FILTER_LOGIC_CONTAINS
        See Also:
        Constant Field Values
      • ATTR_FILTER_LOGIC_STARTS_WITH

        public static final java.lang.String ATTR_FILTER_LOGIC_STARTS_WITH
        See Also:
        Constant Field Values
    • Constructor Detail

      • Chosenbox

        public Chosenbox()
    • Method Detail

      • getZclass

        public java.lang.String getZclass()
        Overrides:
        getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
      • 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> org.zkoss.zul.ItemRenderer<T> getRealRenderer()
      • getItemRenderer

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

        public <T> org.zkoss.zul.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​(org.zkoss.zul.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:
        org.zkoss.zk.ui.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()
        Overrides:
        isChildable in class org.zkoss.zk.ui.AbstractComponent
      • setItemRenderer

        public void setItemRenderer​(org.zkoss.zul.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:
        org.zkoss.zk.ui.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()
        Specified by:
        invalidate in interface org.zkoss.zk.ui.Component
        Overrides:
        invalidate in class org.zkoss.zk.ui.AbstractComponent
      • clone

        public java.lang.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
      • renderProperties

        protected void renderProperties​(org.zkoss.zk.ui.sys.ContentRenderer renderer)
                                 throws java.io.IOException
        Overrides:
        renderProperties in class org.zkoss.zk.ui.HtmlBasedComponent
        Throws:
        java.io.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
      • getExtraCtrl

        public java.lang.Object getExtraCtrl()
        Specified by:
        getExtraCtrl in interface org.zkoss.zk.ui.sys.ComponentCtrl
        Overrides:
        getExtraCtrl in class org.zkoss.zk.ui.HtmlBasedComponent
      • 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