Class Selectbox
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zk.ui.HtmlBasedComponent
-
- org.zkoss.zul.Selectbox
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Component,Disable,Scope,ComponentCtrl
public class Selectbox extends HtmlBasedComponent implements Disable
A light weight dropdown list.Default
getZclass(): z-selectbox. It does not create child widgets for each data, so the memory usage is much lower at the server. However, the implementation is based on HTML SELECT and OPTION tags, so the functionality is not as rich asListbox.- Since:
- 6.0.0
- Author:
- jumperchen
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classSelectbox.ExtraCtrlA utility class to implementHtmlBasedComponent.getExtraCtrl().-
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children, AbstractComponent.ForwardInfo, 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_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 Selectbox()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Clones the component.java.lang.ObjectgetExtraCtrl()Returns the client control for this component.<T> ItemRenderer<T>getItemRenderer()Returns the renderer to render each item, or null if the default renderer is used.<T> ListModel<T>getModel()Returns the model associated with this selectbox, or null if this selectbox is not associated with any list data model.java.lang.StringgetName()Returns the name of this component.<T> ItemRenderer<T>getRealRenderer()intgetSelectedIndex()Returns the index of the selected item (-1 if no one is selected).java.lang.StringgetZclass()Returns the ZK Cascading Style class for this component.voidinvalidate()Invalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later.protected booleanisChildable()Returns whether this component can have a child.booleanisDisabled()Returns whether it is disabled.voidonInitRender()voidonInitRenderNow()voidonPageAttached(Page newpage, Page oldpage)Default: handles special event listeners.voidonPageDetached(Page page)Default: handles special event listeners.protected voidrenderProperties(ContentRenderer renderer)Renders the content of this component, excluding the enclosing tags and children.voidservice(AuRequest request, boolean everError)Processes an AU request.voidsessionDidActivate(Page page)Notification that the session, which owns this component, has just been activated (a.k.a., deserialized).voidsessionWillPassivate(Page page)Notification that the session, which owns this component, is about to be passivated (a.k.a., serialized).voidsetDisabled(boolean disabled)Sets whether it is disabled.voidsetItemRenderer(java.lang.String clsnm)Sets the renderer by use of a class name.voidsetItemRenderer(ItemRenderer<?> renderer)Sets the renderer which is used to render each item ifgetModel()is not null.voidsetModel(ListModel<?> model)Sets the list model associated with this selectbox.voidsetName(java.lang.String name)Sets the name of this component.voidsetParent(Component parent)Sets the parent component.voidsetSelectedIndex(int jsel)Selects the item with the given index.-
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, 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
-
-
-
-
Method Detail
-
getZclass
public java.lang.String getZclass()
Description copied from class:HtmlBasedComponentReturns the ZK Cascading Style class for this component. It usually depends on the implementation of the mold (AbstractComponent.getMold()).Default: null (the default value depends on element).
HtmlBasedComponent.setZclass(java.lang.String)) will completely replace the default style of a component. In other words, the default style of a component is associated with the default value ofHtmlBasedComponent.getZclass(). Once it is changed, the default style won't be applied at all. If you want to perform small adjustments, useHtmlBasedComponent.setSclass(java.lang.String)instead.- Overrides:
getZclassin classHtmlBasedComponent- See Also:
HtmlBasedComponent.getSclass()
-
getSelectedIndex
public int getSelectedIndex()
Returns the index of the selected item (-1 if no one is selected).
-
setSelectedIndex
public void setSelectedIndex(int jsel)
Selects the item with the given index.
-
getItemRenderer
public <T> ItemRenderer<T> getItemRenderer()
Returns the renderer to render each item, or null if the default renderer is used.
-
setItemRenderer
public void setItemRenderer(ItemRenderer<?> renderer)
Sets the renderer which is used to render each item ifgetModel()is not null.Note: changing a render will not cause the selectbox to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(null) and than setModel(oldModel)), or fire an
ListDataEventevent.- 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.InvocationTargetExceptionSets the renderer by use of a class name. It creates an instance automatically.- Throws:
java.lang.ClassNotFoundExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.reflect.InvocationTargetException
-
isDisabled
public boolean isDisabled()
Returns whether it is disabled.Default: false.
- Specified by:
isDisabledin interfaceDisable
-
isChildable
protected boolean isChildable()
Description copied from class:AbstractComponentReturns whether this component can have a child.Default: return true (means it can have children).
- Overrides:
isChildablein classAbstractComponent
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether it is disabled.- Specified by:
setDisabledin interfaceDisable
-
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 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.
-
setModel
public void setModel(ListModel<?> model)
Sets the list model associated with this selectbox. 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 dissociate any previous model.- Throws:
UiException- if failed to initialize with the model
-
onInitRender
public void onInitRender()
-
onInitRenderNow
public void onInitRenderNow()
-
getModel
public <T> ListModel<T> getModel()
Returns the model associated with this selectbox, or null if this selectbox is not associated with any list data model.
-
getRealRenderer
public <T> ItemRenderer<T> getRealRenderer()
-
invalidate
public void invalidate()
Description copied from interface:ComponentInvalidates 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:
invalidatein interfaceComponent- Overrides:
invalidatein classAbstractComponent
-
setParent
public void setParent(Component parent)
Description copied from interface:ComponentSets the parent component.Note:
Component.setParent(org.zkoss.zk.ui.Component)always calls backComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)and/orComponent.removeChild(org.zkoss.zk.ui.Component), whileComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.removeChild(org.zkoss.zk.ui.Component)always calls backComponent.setParent(org.zkoss.zk.ui.Component), if the parent is changed. Thus, you don't need to override bothComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.setParent(org.zkoss.zk.ui.Component), if you want to customize the behavior.- Specified by:
setParentin interfaceComponent- Overrides:
setParentin classAbstractComponent
-
onPageAttached
public void onPageAttached(Page newpage, Page oldpage)
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onPageAttachedin interfaceComponentCtrl- Overrides:
onPageAttachedin classAbstractComponent- Parameters:
newpage- the new page (never null).oldpage- the previous page, if any, or null if it didn't belong to any page.- See Also:
ComponentCtrl.onPageAttached(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Page)
-
onPageDetached
public void onPageDetached(Page page)
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onPageDetachedin interfaceComponentCtrl- Overrides:
onPageDetachedin classAbstractComponent- Parameters:
page- the previous page (never null)- See Also:
ComponentCtrl.onPageDetached(org.zkoss.zk.ui.Page)
-
renderProperties
protected void renderProperties(ContentRenderer renderer) throws java.io.IOException
Description copied from class:HtmlBasedComponentRenders the content of this component, excluding the enclosing tags and children.- Overrides:
renderPropertiesin classHtmlBasedComponent- Throws:
java.io.IOException
-
service
public void service(AuRequest request, boolean everError)
Description copied from class:HtmlBasedComponentProcesses an AU request.Default: it handles onClick, onDoubleClick, onRightClick onMove, onSize, onZIndex.
- Specified by:
servicein interfaceComponentCtrl- Overrides:
servicein classHtmlBasedComponenteverError- whether any error ever occurred before processing this request.- See Also:
AbstractComponent.setAuService(org.zkoss.zk.au.AuService)
-
clone
public java.lang.Object clone()
Description copied from interface:ComponentClones the component. All of its children and descendants are cloned. Also, ID are preserved.- Specified by:
clonein interfaceComponent- Overrides:
clonein classHtmlBasedComponent- Returns:
- the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
-
sessionWillPassivate
public void sessionWillPassivate(Page page)
Description copied from interface:ComponentCtrlNotification that the session, which owns this component, is about to be passivated (a.k.a., serialized).Note: only root components are notified by this method.
- Specified by:
sessionWillPassivatein interfaceComponentCtrl- Overrides:
sessionWillPassivatein classAbstractComponent
-
sessionDidActivate
public void sessionDidActivate(Page page)
Description copied from interface:ComponentCtrlNotification that the session, which owns this component, has just been activated (a.k.a., deserialized).Note: only root components are notified by this method.
- Specified by:
sessionDidActivatein interfaceComponentCtrl- Overrides:
sessionDidActivatein classAbstractComponent
-
getExtraCtrl
public java.lang.Object getExtraCtrl()
Description copied from class:HtmlBasedComponentReturns the client control for this component. It is used only by component developers.Default: creates an instance of
HtmlBasedComponent.ExtraCtrl.- Specified by:
getExtraCtrlin interfaceComponentCtrl- Overrides:
getExtraCtrlin classHtmlBasedComponent- Returns:
- null if no special handling required. If the component
requires some special controls, it could return an object that
implements one or several interfaces in the org.zkoss.zk.ui.ext.render
package.
For example,
Cropper. - See Also:
ComponentCtrl.getExtraCtrl()
-
-