Module org.apache.wicket.core
Class AbstractSingleSelectChoice<T>
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,T>
org.apache.wicket.markup.html.form.AbstractSingleSelectChoice<T>
- Type Parameters:
T
- The model object type
- 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:
DropDownChoice
,RadioChoice
Abstract base class for single-select choices.
- Author:
- Jonathan Locke, Eelco Hillenius nm, Johan Compagner
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.wicket.markup.html.form.AbstractChoice
AbstractChoice.LabelPosition
-
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
ConstructorDescriptionConstructor.AbstractSingleSelectChoice
(String id, List<? extends T> choices) Constructor.AbstractSingleSelectChoice
(String id, List<? extends T> choices, IChoiceRenderer<? super T> renderer) Constructor.AbstractSingleSelectChoice
(String id, IModel<? extends List<? extends T>> choices) Constructor.AbstractSingleSelectChoice
(String id, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) Constructor.Constructor.AbstractSingleSelectChoice
(String id, IModel<T> model, List<? extends T> choices, IChoiceRenderer<? super T> renderer) Constructor.Constructor.AbstractSingleSelectChoice
(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected T
Converts submitted choice id string back to choice object.protected final T
convertValue
(String[] value) Subclasses should overwrite this if the conversion is not done through the type field and theIConverter
.protected CharSequence
getDefaultChoice
(String selectedValue) Asks theLocalizer
for the property to display for an additional default choice depending onisNullValid()
: "nullValid" ifnull
is valid, defaulting to an empty string. "null" ifnull
is not valid but no choice is selected (i.e.protected String
Return the localization key for null valueprotected String
Returns the display value if null is not valid but is selected.protected String
Returns the display value for the null value.protected String
Return the localization key for nullValid valueboolean
Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g.protected boolean
isSelected
(T object, int index, String selected) Gets whether the given value represents the current selection.setNullValid
(boolean nullValid) Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g.Methods inherited from class org.apache.wicket.markup.html.form.AbstractChoice
appendOptionHtml, detachModel, escapeOptionHtml, getChoiceRenderer, getChoices, getChoicesModel, isDisabled, localizeDisplayValues, onComponentTagBody, onDetach, setChoiceRenderer, setChoices, setChoices, setOptionAttributes, setType
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, checkRequired, clearInput, convertInput, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInput, getInputAsArray, getInputName, 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
-
AbstractSingleSelectChoice
Constructor.- Parameters:
id
- See Component
-
AbstractSingleSelectChoice
Constructor.- Parameters:
id
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractSingleSelectChoice
public AbstractSingleSelectChoice(String id, List<? extends T> choices, IChoiceRenderer<? super T> renderer) Constructor.- Parameters:
id
- See Componentrenderer
- The rendering enginechoices
- The collection of choices in the dropdown
-
AbstractSingleSelectChoice
Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractSingleSelectChoice
public AbstractSingleSelectChoice(String id, IModel<T> model, List<? extends T> choices, IChoiceRenderer<? super T> renderer) Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The drop down choicesrenderer
- The rendering engine
-
AbstractSingleSelectChoice
Constructor.- Parameters:
id
- See Componentchoices
- The collection of choices in the dropdown
-
AbstractSingleSelectChoice
public AbstractSingleSelectChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices) Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The drop down choices
-
AbstractSingleSelectChoice
public AbstractSingleSelectChoice(String id, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) Constructor.- Parameters:
id
- See Componentchoices
- The drop down choicesrenderer
- The rendering engine
-
AbstractSingleSelectChoice
public AbstractSingleSelectChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) Constructor.- Parameters:
id
- See Componentmodel
- See Componentchoices
- The drop down choicesrenderer
- The rendering engine
-
-
Method Details
-
getModelValue
- Overrides:
getModelValue
in classFormComponent<T>
- Returns:
- Value to return when model value is needed
- See Also:
-
isNullValid
Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g. "Choose One") should be displayed until a nonnull value is selected. If set to false, then "Choose One" will be displayed when the value is null. After a value is selected, and that change is propagated to the underlying model, the user will no longer see the "Choose One" option, and there will be no way to reselect null as the value. If set to true, the null string property (the empty string, by default) will always be displayed as an option, whether or not a nonnull value has ever been selected. Note that this setting has no effect on validation; in order to guarantee that a value will be specified on form validation,FormComponent.setRequired(boolean)
. This is because even if setNullValid() is called with false, the user can fail to provide a value simply by never activating (i.e. clicking on) the component.- Returns:
true
when thenull
value is allowed.
-
setNullValid
Determines whether or not the null value should be included in the list of choices when the field's model value is nonnull, and whether or not the null_valid string property (e.g. "Choose One") should be displayed until a nonnull value is selected. If set to false, then "Choose One" will be displayed when the value is null. After a value is selected, and that change is propagated to the underlying model, the user will no longer see the "Choose One" option, and there will be no way to reselect null as the value. If set to true, the null string property (the empty string, by default) will always be displayed as an option, whether or not a nonnull value has ever been selected. Note that this setting has no effect on validation; in order to guarantee that a value will be specified on form validation,FormComponent.setRequired(boolean)
. This is because even if setNullValid() is called with false, the user can fail to provide a value simply by never activating (i.e. clicking on) the component.- Parameters:
nullValid
- whether null is a valid value- Returns:
- this for chaining
-
convertValue
Description copied from class:FormComponent
Subclasses should overwrite this if the conversion is not done through the type field and theIConverter
. WARNING: this method may be removed in future versions. If conversion fails then a ConversionException should be thrown- Overrides:
convertValue
in classFormComponent<T>
- Parameters:
value
- The value can be the getInput() or through a cookie- Returns:
- The converted value. default returns just the given value
- See Also:
-
convertChoiceIdToChoice
Converts submitted choice id string back to choice object.- Parameters:
id
- string id of one of the choice objects in the choices list. can be null.- Returns:
- choice object. null if none match the specified id.
-
getDefaultChoice
Asks theLocalizer
for the property to display for an additional default choice depending onisNullValid()
:-
"nullValid" if
null
is valid, defaulting to an empty string. -
"null" if
null
is not valid but no choice is selected (i.e.selectedValue
is empty), defaulting to "Choose one".
- Overrides:
getDefaultChoice
in classAbstractChoice<T,
T> - Parameters:
selectedValue
- The currently selected value- Returns:
- Any default choice, such as "Choose One", depending on the subclass
- See Also:
-
"nullValid" if
-
getNullValidDisplayValue
Returns the display value for the null value. The default behavior is to look the value up by using the key fromgetNullValidKey()
.- Returns:
- The value to display for null
-
getNullValidKey
Return the localization key for nullValid value- Returns:
- getId() + ".nullValid"
-
getNullKeyDisplayValue
Returns the display value if null is not valid but is selected. The default behavior is to look the value up by using the key fromgetNullKey()
.- Returns:
- The value to display if null is not value but selected, e.g. "Choose One"
-
getNullKey
Return the localization key for null value- Returns:
- getId() + ".null"
-
isSelected
Gets whether the given value represents the current selection.- Specified by:
isSelected
in classAbstractChoice<T,
T> - Parameters:
object
- The object to checkindex
- The index of the object in the collectionselected
- The current selected id value- Returns:
- Whether the given value represents the current selection
-