org.apache.wicket.markup.html.form
Class AbstractSingleSelectChoice<T>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
                  extended by org.apache.wicket.markup.html.form.FormComponent<T>
                      extended by org.apache.wicket.markup.html.form.AbstractChoice<T,T>
                          extended by org.apache.wicket.markup.html.form.AbstractSingleSelectChoice<T>
Type Parameters:
T - The model object type
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Component>, IEventSink, IEventSource, IClusterable, IConverterLocator, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<java.lang.String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
DropDownChoice, RadioChoice

public abstract class AbstractSingleSelectChoice<T>
extends AbstractChoice<T,T>

Abstract base class for single-select choices.

Author:
Jonathan Locke, Eelco Hillenius nm, Johan Compagner
See Also:
Serialized Form

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_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
AbstractSingleSelectChoice(java.lang.String id)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<? extends java.util.List<? extends T>> choices)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<? extends java.util.List<? extends T>> choices, IChoiceRenderer<? super T> renderer)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<T> model, IModel<? extends java.util.List<? extends T>> choices)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<T> model, IModel<? extends java.util.List<? extends T>> choices, IChoiceRenderer<? super T> renderer)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<T> model, java.util.List<? extends T> choices)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, IModel<T> model, java.util.List<? extends T> choices, IChoiceRenderer<? super T> renderer)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, java.util.List<? extends T> choices)
          Constructor.
AbstractSingleSelectChoice(java.lang.String id, java.util.List<? extends T> choices, IChoiceRenderer<? super T> renderer)
          Constructor.
 
Method Summary
protected  T convertChoiceIdToChoice(java.lang.String id)
          Converts submitted choice id string back to choice object.
protected  T convertValue(java.lang.String[] value)
          Subclasses should overwrite this if the conversion is not done through the type field and the IConverter.
protected  java.lang.CharSequence getDefaultChoice(java.lang.String selectedValue)
          Asks the Localizer for the property to display for an additional default choice depending on isNullValid(): "nullValid" if null is valid, defaulting to an empty string. "null" if null is not valid but no choice is selected (i.e.
 java.lang.String getModelValue()
           
protected  java.lang.String getNullKey()
          Return the localization key for null value
protected  java.lang.String getNullValidKey()
          Return the localization key for nullValid value
 boolean 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.
protected  boolean isSelected(T object, int index, java.lang.String selected)
          Gets whether the given value represents the current selection.
 AbstractSingleSelectChoice<T> 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, isDisabled, localizeDisplayValues, onComponentTagBody, setChoiceRenderer, setChoices, setChoices, 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, getModel, getModelObject, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isMultiPart, isRequired, isValid, newValidatable, onComponentTag, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, remove, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setRequired, shouldTrimInput, trim, updateCollectionModel, updateModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
 
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel, setLabelInternal
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, hasAssociatedMarkup, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onMarkupAttached, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, 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, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onConfigure, onEvent, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id)
Constructor.

Parameters:
id - See Component

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  java.util.List<? extends T> choices)
Constructor.

Parameters:
id - See Component
choices - The collection of choices in the dropdown

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  java.util.List<? extends T> choices,
                                  IChoiceRenderer<? super T> renderer)
Constructor.

Parameters:
id - See Component
renderer - The rendering engine
choices - The collection of choices in the dropdown

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<T> model,
                                  java.util.List<? extends T> choices)
Constructor.

Parameters:
id - See Component
model - See Component
choices - The collection of choices in the dropdown

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<T> model,
                                  java.util.List<? extends T> choices,
                                  IChoiceRenderer<? super T> renderer)
Constructor.

Parameters:
id - See Component
model - See Component
choices - The drop down choices
renderer - The rendering engine

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<? extends java.util.List<? extends T>> choices)
Constructor.

Parameters:
id - See Component
choices - The collection of choices in the dropdown

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<T> model,
                                  IModel<? extends java.util.List<? extends T>> choices)
Constructor.

Parameters:
id - See Component
model - See Component
choices - The drop down choices

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<? extends java.util.List<? extends T>> choices,
                                  IChoiceRenderer<? super T> renderer)
Constructor.

Parameters:
id - See Component
choices - The drop down choices
renderer - The rendering engine

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(java.lang.String id,
                                  IModel<T> model,
                                  IModel<? extends java.util.List<? extends T>> choices,
                                  IChoiceRenderer<? super T> renderer)
Constructor.

Parameters:
id - See Component
model - See Component
choices - The drop down choices
renderer - The rendering engine
Method Detail

getModelValue

public java.lang.String getModelValue()
Overrides:
getModelValue in class FormComponent<T>
Returns:
Value to return when model value is needed
See Also:
FormComponent.getModelValue()

isNullValid

public boolean 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 the null value is allowed.

setNullValid

public AbstractSingleSelectChoice<T> 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. "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

protected final T convertValue(java.lang.String[] value)
Description copied from class: FormComponent
Subclasses should overwrite this if the conversion is not done through the type field and the IConverter. WARNING: this method may be removed in future versions. If conversion fails then a ConversionException should be thrown

Overrides:
convertValue in class FormComponent<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:
FormComponent.convertValue(String[])

convertChoiceIdToChoice

protected T convertChoiceIdToChoice(java.lang.String id)
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

protected java.lang.CharSequence getDefaultChoice(java.lang.String selectedValue)
Asks the Localizer for the property to display for an additional default choice depending on isNullValid(): Otherwise no additional default choice will be returned.

Overrides:
getDefaultChoice in class AbstractChoice<T,T>
Parameters:
selectedValue - The currently selected value
Returns:
Any default choice, such as "Choose One", depending on the subclass
See Also:
getNullValidKey(), getNullKey(), AbstractChoice.getDefaultChoice(String)

getNullValidKey

protected java.lang.String getNullValidKey()
Return the localization key for nullValid value

Returns:
getId() + ".nullValid"

getNullKey

protected java.lang.String getNullKey()
Return the localization key for null value

Returns:
getId() + ".null"

isSelected

protected boolean isSelected(T object,
                             int index,
                             java.lang.String selected)
Gets whether the given value represents the current selection. aram object The object to check

Specified by:
isSelected in class AbstractChoice<T,T>
Parameters:
index - The index of the object in the collection
selected - The current selected id value
object - The object to check
Returns:
Whether the given value represents the current selection


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.