java.lang.Object
org.apache.wicket.Component
org.apache.wicket.MarkupContainer
org.apache.wicket.markup.html.WebMarkupContainer
org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
org.apache.wicket.markup.html.form.FormComponent<T>
org.apache.wicket.markup.html.form.AbstractChoice<T,E>
- Type Parameters:
T
- The model object typeE
- class of a single element in the choices list
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IGenericComponent<T,
,FormComponent<T>> IMetadataContext<Serializable,
,Component> IFormModelUpdateListener
,IFormVisitorParticipant
,ILabelProvider<String>
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
AbstractSingleSelectChoice
,ListMultipleChoice
Abstract base class for all choice (html select) options.
This component uses String concatenation to keep its memory footprint light. Use Select, SelectOptions and SelectOption from wicket-extensions for more sophisticated needs.
- Author:
- Jonathan Locke, Eelco Hillenius, Johan Compagner
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
An enumeration of possible positions of the label for a choice -
Field Summary
Fields inherited from class org.apache.wicket.markup.html.form.FormComponent
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, VALUE_SEPARATOR
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
Constructor Summary
ConstructorDescriptionAbstractChoice
(String id) Constructor.AbstractChoice
(String id, List<? extends E> choices) Constructor.AbstractChoice
(String id, List<? extends E> choices, IChoiceRenderer<? super E> renderer) Constructor.AbstractChoice
(String id, IModel<? extends List<? extends E>> choices) Constructor.AbstractChoice
(String id, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer) Constructor.Constructor.AbstractChoice
(String id, IModel<T> model, List<? extends E> choices, IChoiceRenderer<? super E> renderer) Constructor.Constructor.AbstractChoice
(String id, IModel<T> model, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
appendOptionHtml
(AppendingStringBuffer buffer, E choice, int index, String selected) Generates and appends html for a single choice into the provided bufferprotected void
Detaches the model for this component if it is detachable.protected CharSequence
escapeOptionHtml
(String displayValue) Method to override if you want special escaping of the options html.final IChoiceRenderer<? super E>
protected CharSequence
getDefaultChoice
(String selectedValue) Get a default choice to be rendered additionally to the choices available in the model.protected boolean
isDisabled
(E object, int index, String selected) Gets whether the given value is disabled.protected abstract boolean
isSelected
(E object, int index, String selected) Gets whether the given value represents the current selection.protected boolean
Override this method if you want to localize the display values of the generated options.void
onComponentTagBody
(MarkupStream markupStream, ComponentTag openTag) Handle the container's body.protected void
onDetach()
Sets the temporary converted input value to null.final AbstractChoice<T,
E> setChoiceRenderer
(IChoiceRenderer<? super E> renderer) Set the choice renderer to be used.final AbstractChoice<T,
E> setChoices
(List<? extends E> choices) Sets the list of choices.final AbstractChoice<T,
E> setChoices
(IModel<? extends List<? extends E>> choices) Sets the list of choicesprotected void
setOptionAttributes
(AppendingStringBuffer buffer, E choice, int index, String selected) Sets the attributes of a single choice into the provided buffer.final FormComponent<T>
Sets the type that will be used when updating the model for this component.Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, checkRequired, clearInput, convertInput, convertValue, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInput, getInputAsArray, getInputName, getModelValue, getParameterValues, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isMultiPart, isRequired, isValid, newValidatable, newValidationError, onBeforeRender, onComponentTag, onDisabled, onInvalid, onValid, processChildren, processInput, remove, reportRequiredError, setConvertedInput, setLabel, setModelValue, setRequired, shouldTrimInput, trim, updateAutoLabels, updateAutoLabels, updateCollectionModel, updateModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModel, setDefaultModelObject, setModel, setModelObject
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AbstractChoice
Constructor.- Parameters:
id
- See Component
-
AbstractChoice
Constructor.- Parameters:
id
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractChoice
Constructor.- Parameters:
id
- See Componentrenderer
- The rendering enginechoices
- The collection of choices in the dropdown
-
AbstractChoice
Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractChoice
public AbstractChoice(String id, IModel<T> model, List<? extends E> choices, IChoiceRenderer<? super E> renderer) Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The drop down choicesrenderer
- The rendering engine
-
AbstractChoice
Constructor.- Parameters:
id
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractChoice
public AbstractChoice(String id, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer) Constructor.- Parameters:
id
- See Componentrenderer
- The rendering enginechoices
- The collection of choices in the dropdown
-
AbstractChoice
Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractChoice
public AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer) Constructor.- Parameters:
id
- See Componentmodel
- See Componentrenderer
- The rendering enginechoices
- The drop down choices
-
-
Method Details
-
getChoices
- Returns:
- The collection of object that this choice has
-
getChoicesModel
- Returns:
- The model with the choices for this component
-
setChoices
Sets the list of choices- Parameters:
choices
- model representing the list of choices- Returns:
- this for chaining
-
setChoices
Sets the list of choices.- Parameters:
choices
- the list of choices- Returns:
- this for chaining
-
getChoiceRenderer
- Returns:
- The IChoiceRenderer used for rendering the data objects
-
setChoiceRenderer
Set the choice renderer to be used.- Parameters:
renderer
- The IChoiceRenderer used for rendering the data objects- Returns:
- this for chaining
-
detachModel
Description copied from class:Component
Detaches the model for this component if it is detachable.- Overrides:
detachModel
in classComponent
-
getDefaultChoice
Get a default choice to be rendered additionally to the choices available in the model.- Parameters:
selectedValue
- The currently selected value- Returns:
- Any default choice, such as "Choose One", depending on the subclass
- See Also:
-
isSelected
Gets whether the given value represents the current selection.- Parameters:
object
- The object to checkindex
- The index in the choices collection this object is in.selected
- The currently selected string value- Returns:
- Whether the given value represents the current selection
-
isDisabled
Gets whether the given value is disabled. This default implementation always returns false.- Parameters:
object
- The object to checkindex
- The index in the choices collection this object is in.selected
- The currently selected string value- Returns:
- Whether the given value represents the current selection
-
onComponentTagBody
Handle the container's body.- Overrides:
onComponentTagBody
in classMarkupContainer
- Parameters:
markupStream
- The markup streamopenTag
- The open tag for the body
-
appendOptionHtml
Generates and appends html for a single choice into the provided buffer- Parameters:
buffer
- Appending string buffer that will have the generated html appendedchoice
- Choice objectindex
- The index of this optionselected
- The currently selected string value
-
setOptionAttributes
protected void setOptionAttributes(AppendingStringBuffer buffer, E choice, int index, String selected) Sets the attributes of a single choice into the provided buffer.- Parameters:
buffer
- Appending string buffer that will have the generated html appendedchoice
- Choice objectindex
- The index of this optionselected
- The currently selected string value
-
escapeOptionHtml
Method to override if you want special escaping of the options html.- Parameters:
displayValue
-- Returns:
- The escaped display value
-
localizeDisplayValues
Override this method if you want to localize the display values of the generated options. By default false is returned so that the display values of options are not tested if they have a i18n key.- Returns:
- true If you want to localize the display values, default == false
-
setType
Description copied from class:FormComponent
Sets the type that will be used when updating the model for this component. If no type is specified String type is assumed.- Overrides:
setType
in classFormComponent<T>
- Returns:
- this for chaining
-
onDetach
Description copied from class:FormComponent
Sets the temporary converted input value to null.- Overrides:
onDetach
in classFormComponent<T>
- See Also:
-