org.zkoss.zul.api
Interface Combobox

All Superinterfaces:
java.lang.Cloneable, Component, Constrainted, HtmlBasedComponent, InputElement, Scope, java.io.Serializable, Textbox, XulElement
All Known Implementing Classes:
Combobox

public interface Combobox
extends Textbox

A combo box.

Non-XUL extension. It is used to replace XUL menulist. This class is more flexible than menulist, such as setAutocomplete(boolean) setAutodrop(boolean).

Default HtmlBasedComponent.getZclass(): z-combobox.(since 3.5.0)

Events: onOpen, onSelect
Developers can listen to the onOpen event and initializes it when OpenEvent.isOpen() is true, and/or clean up if false. *

Besides assign a list model, you could assign a renderer (a ComboitemRenderer instance) to a combobox, such that the combobox will use this renderer to render the data returned by ListModel.getElementAt(int). If not assigned, the default renderer, which assumes a label per combo item, is used. In other words, the default renderer adds a label to a row by calling toString against the object returned by ListModel.getElementAt(int).

Note: to have better performance, onOpen is sent only if a non-deferrable event listener is registered (see Deferrable).

Like Datebox, the value of a read-only comobobox (InputElement.isReadonly() ) can be changed by dropping down the list and selecting an combo item (though users cannot type anything in the input box).

Since:
3.5.2
Author:
tomyeh
See Also:
Comboitem

Field Summary
 
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
 
Method Summary
 Comboitem appendItemApi(java.lang.String label)
          Appends an item.
 void close()
          Closes the list of combo items (Comboitem if it was dropped down.
 Comboitem getItemAtIndexApi(int index)
          Returns the item at the specified index.
 int getItemCount()
          Returns the number of items.
 ComboitemRenderer getItemRenderer()
          Returns the renderer to render each row, or null if the default renderer is used.
 java.util.List getItems()
          Returns a 'live' list of all Comboitem.
 ListModel getModel()
          Returns the list model associated with this combobox, or null if this combobox is not associated with any list data model.
 int getSelectedIndex()
          Returns the index of the selected item, or -1 if not selected.
 Comboitem getSelectedItemApi()
          Returns the selected item.
 boolean isAutocomplete()
          Returns whether to automatically complete this text box by matching the nearest item (Comboitem.
 boolean isAutodrop()
          Returns whether to automatically drop the list if users is changing this text box.
 boolean isButtonVisible()
          Returns whether the button (on the right of the textbox) is visible.
 void open()
          Drops down the list of combo items (Comboitem.
 Comboitem removeItemAtApi(int index)
          Removes the child item in the list box at the given index.
 void setAutocomplete(boolean autocomplete)
          Sets whether to automatically complete this text box by matching the nearest item (Comboitem.
 void setAutodrop(boolean autodrop)
          Sets whether to automatically drop the list if users is changing this text box.
 void setButtonVisible(boolean visible)
          Sets whether the button (on the right of the textbox) is visible.
 void setItemRenderer(ComboitemRenderer renderer)
          Sets the renderer which is used to render each row if getModel() is not null.
 void setItemRenderer(java.lang.String clsnm)
          Sets the renderer by use of a class name.
 void setModel(ListModel model)
          Sets the list model associated with this combobox.
 void setOpen(boolean open)
          Drops down or closes the list of combo items (Comboitem.
 void setSelectedIndex(int jsel)
          Deselects the currently selected items and selects the item with the given index.
 void setSelectedItemApi(Comboitem item)
          Deselects the currently selected items and selects the given item.
 
Methods inherited from interface org.zkoss.zul.api.Textbox
getRows, getValue, setMultiline, setRows, setType, setValue
 
Methods inherited from interface org.zkoss.zul.impl.api.InputElement
clearErrorMessage, clearErrorMessage, getCols, getErrorMessage, getMaxlength, getName, getRawText, getRawValue, getTabindex, getText, getType, isDisabled, isMultiline, isReadonly, isValid, select, setCols, setConstraint, setDisabled, setMaxlength, setName, setRawValue, setReadonly, setSelectedText, setSelectionRange, setTabindex, setText
 
Methods inherited from interface org.zkoss.zul.impl.api.XulElement
getAction, getContext, getCtrlKeys, getPopup, getTooltip, setAction, setContext, setContext, setCtrlKeys, setPopup, setPopup, setTooltip, setTooltip
 
Methods inherited from interface org.zkoss.zk.ui.api.HtmlBasedComponent
focus, getHeight, getLeft, getSclass, getStyle, getTooltiptext, getTop, getWidth, getZclass, getZindex, getZIndex, setDraggable, setDroppable, setFocus, setHeight, setLeft, setSclass, setStyle, setTooltiptext, setTop, setWidth, setZclass, setZindex, setZIndex
 
Methods inherited from interface org.zkoss.zk.ui.Component
addEventListener, addForward, addForward, addForward, addForward, appendChild, applyProperties, clone, containsVariable, detach, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getChildren, getDefinition, getDesktop, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getNamespace, getNextSibling, getPage, getParent, getPreviousSibling, getRoot, getSpaceOwner, getUuid, getVariable, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttributeOrFellow, hasFellow, hasFellow, insertBefore, invalidate, isInvalidated, isListenerAvailable, isVisible, removeAttribute, removeAttribute, removeChild, removeEventListener, removeForward, removeForward, setAttribute, setAttribute, setAuService, setId, setMold, setPage, setPageBefore, setParent, setVariable, setVisible, setWidgetListener, setWidgetOverride, unsetVariable
 
Methods inherited from interface org.zkoss.zk.ui.ext.Scope
addScopeListener, getAttribute, hasAttribute, removeAttribute, removeScopeListener, setAttribute
 
Methods inherited from interface org.zkoss.zul.ext.Constrainted
getConstraint, setConstraint
 

Method Detail

getModel

ListModel getModel()
Returns the list model associated with this combobox, or null if this combobox is not associated with any list data model.

Note: for implementation of auto-complete, the result of getItemCount() is a subset of model. So, if the model implemented ListSubModel interface, you can't use the index of model to find the comboitem by getItemAtIndexApi(int).

See Also:
ListSubModel.getSubModel(Object, int)

setModel

void setModel(ListModel model)
Sets the list model associated with this combobox. 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

getItemRenderer

ComboitemRenderer getItemRenderer()
Returns the renderer to render each row, or null if the default renderer is used.


setItemRenderer

void setItemRenderer(ComboitemRenderer renderer)
Sets the renderer which is used to render each row if getModel() is not null.

Note: changing a render will not cause the combobox 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

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

isAutodrop

boolean isAutodrop()
Returns whether to automatically drop the list if users is changing this text box.

Default: false.


setAutodrop

void setAutodrop(boolean autodrop)
Sets whether to automatically drop the list if users is changing this text box.


isAutocomplete

boolean isAutocomplete()
Returns whether to automatically complete this text box by matching the nearest item (Comboitem.

Default: false.

If true, the nearest item will be searched and the text box is updated automatically. If false, user has to click the item or use the DOWN or UP keys to select it back.

Note: this feature is reserved and not yet implemented. Don't confuse it with the auto-completion feature mentioned by other framework. Such kind of auto-completion is supported well by listening to the onChanging event.


setAutocomplete

void setAutocomplete(boolean autocomplete)
Sets whether to automatically complete this text box by matching the nearest item (Comboitem.


setOpen

void setOpen(boolean open)
Drops down or closes the list of combo items (Comboitem.

See Also:
open(), close()

open

void open()
Drops down the list of combo items (Comboitem. It is the same as setOpen(true).


close

void close()
Closes the list of combo items (Comboitem if it was dropped down. It is the same as setOpen(false).


isButtonVisible

boolean isButtonVisible()
Returns whether the button (on the right of the textbox) is visible.

Default: true.


setButtonVisible

void setButtonVisible(boolean visible)
Sets whether the button (on the right of the textbox) is visible.


getItems

java.util.List getItems()
Returns a 'live' list of all Comboitem. By live we mean you can add or remove them directly with the List interface.

Currently, it is the same as Component.getChildren(). However, we might add other kind of children in the future.


getItemCount

int getItemCount()
Returns the number of items.


getItemAtIndexApi

Comboitem getItemAtIndexApi(int index)
Returns the item at the specified index.


appendItemApi

Comboitem appendItemApi(java.lang.String label)
Appends an item.


removeItemAtApi

Comboitem removeItemAtApi(int index)
Removes the child item in the list box at the given index.

Returns:
the removed item.

getSelectedItemApi

Comboitem getSelectedItemApi()
Returns the selected item.


setSelectedItemApi

void setSelectedItemApi(Comboitem item)
Deselects the currently selected items and selects the given item.

Note: if the label of comboitem has the same more than one, the first comboitem will be selected at client side, it is a limitation of Combobox and it is different from Listbox.


setSelectedIndex

void setSelectedIndex(int jsel)
Deselects the currently selected items and selects the item with the given index.

Note: if the label of comboitem has the same more than one, the first comboitem will be selected at client side, it is a limitation of Combobox and it is different from Listbox.


getSelectedIndex

int getSelectedIndex()
Returns the index of the selected item, or -1 if not selected.



Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo