Class AbstractChoice<T,E>
- 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
public abstract class AbstractChoice<T,E> extends FormComponent<T>
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractChoice.LabelPosition
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
Constructors Constructor Description AbstractChoice(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.AbstractChoice(String id, IModel<T> model, List<? extends E> choices)
Constructor.AbstractChoice(String id, IModel<T> model, List<? extends E> choices, IChoiceRenderer<? super E> renderer)
Constructor.AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices)
Constructor.AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices, IChoiceRenderer<? super E> renderer)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
appendOptionHtml(AppendingStringBuffer buffer, E choice, int index, String selected)
Generates and appends html for a single choice into the provided bufferprotected void
detachModel()
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.IChoiceRenderer<? super E>
getChoiceRenderer()
List<? extends E>
getChoices()
IModel<? extends List<? extends E>>
getChoicesModel()
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
localizeDisplayValues()
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.AbstractChoice<T,E>
setChoiceRenderer(IChoiceRenderer<? super E> renderer)
Set the choice renderer to be used.AbstractChoice<T,E>
setChoices(List<? extends E> choices)
Sets the list of choices.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.FormComponent<T>
setType(Class<?> type)
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, 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 Detail
-
AbstractChoice
public AbstractChoice(String id)
Constructor.- Parameters:
id
- See Component
-
AbstractChoice
public AbstractChoice(String id, List<? extends E> choices)
Constructor.- Parameters:
id
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractChoice
public AbstractChoice(String id, List<? extends E> choices, IChoiceRenderer<? super E> renderer)
Constructor.- Parameters:
id
- See Componentrenderer
- The rendering enginechoices
- The collection of choices in the dropdown
-
AbstractChoice
public AbstractChoice(String id, IModel<T> model, List<? extends E> choices)
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
public AbstractChoice(String id, IModel<? extends List<? extends E>> choices)
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
public AbstractChoice(String id, IModel<T> model, IModel<? extends List<? extends E>> choices)
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 Detail
-
getChoices
public final List<? extends E> getChoices()
- Returns:
- The collection of object that this choice has
-
getChoicesModel
public IModel<? extends List<? extends E>> getChoicesModel()
- Returns:
- The model with the choices for this component
-
setChoices
public final AbstractChoice<T,E> setChoices(IModel<? extends List<? extends E>> choices)
Sets the list of choices- Parameters:
choices
- model representing the list of choices- Returns:
- this for chaining
-
setChoices
public final AbstractChoice<T,E> setChoices(List<? extends E> choices)
Sets the list of choices.- Parameters:
choices
- the list of choices- Returns:
- this for chaining
-
getChoiceRenderer
public final IChoiceRenderer<? super E> getChoiceRenderer()
- Returns:
- The IChoiceRenderer used for rendering the data objects
-
setChoiceRenderer
public final AbstractChoice<T,E> setChoiceRenderer(IChoiceRenderer<? super E> renderer)
Set the choice renderer to be used.- Parameters:
renderer
- The IChoiceRenderer used for rendering the data objects- Returns:
- this for chaining
-
detachModel
protected void detachModel()
Description copied from class:Component
Detaches the model for this component if it is detachable.- Overrides:
detachModel
in classComponent
-
getDefaultChoice
protected CharSequence getDefaultChoice(String selectedValue)
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:
setChoices(IModel)
-
isSelected
protected abstract boolean isSelected(E object, int index, String selected)
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
protected boolean isDisabled(E object, int index, String selected)
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
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
Handle the container's body.- Overrides:
onComponentTagBody
in classMarkupContainer
- Parameters:
markupStream
- The markup streamopenTag
- The open tag for the body
-
appendOptionHtml
protected void appendOptionHtml(AppendingStringBuffer buffer, E choice, int index, String selected)
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
protected CharSequence escapeOptionHtml(String displayValue)
Method to override if you want special escaping of the options html.- Parameters:
displayValue
-- Returns:
- The escaped display value
-
localizeDisplayValues
protected boolean 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
public final FormComponent<T> setType(Class<?> type)
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
protected void onDetach()
Description copied from class:FormComponent
Sets the temporary converted input value to null.- Overrides:
onDetach
in classFormComponent<T>
- See Also:
Component.onDetach()
-
-