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:
Serializable, IClusterable, IConverterLocator, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>
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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.markup.html.form.FormComponent
FormComponent.AbstractVisitor, FormComponent.IVisitor
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.VisibilityChange
 
Field Summary
protected static Object NO_SELECTION_VALUE
           
 
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_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
AbstractSingleSelectChoice(String id)
           
AbstractSingleSelectChoice(String id, IModel<? extends List<? extends T>> choices)
           
AbstractSingleSelectChoice(String id, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer)
           
AbstractSingleSelectChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices)
           
AbstractSingleSelectChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer)
           
AbstractSingleSelectChoice(String id, IModel<T> model, List<? extends T> data)
           
AbstractSingleSelectChoice(String id, IModel<T> model, List<? extends T> data, IChoiceRenderer<? super T> renderer)
           
AbstractSingleSelectChoice(String id, List<? extends T> choices)
           
AbstractSingleSelectChoice(String id, List<? extends T> data, IChoiceRenderer<? super T> renderer)
           
 
Method Summary
protected  T convertChoiceIdToChoice(String id)
          Converts submitted choice id string back to choice object.
protected  T convertValue(String[] value)
          Subclasses should overwrite this if the conversion is not done through the type field and the IConverter.
protected  CharSequence getDefaultChoice(Object selected)
          The localizer will be ask for the property to display Depending on if null is allowed or not it will ask for: nullValid: when null is valid and by default it will show an empty string as a choice. null: when null is not a valid choice and it will make a choice with "Choose One" The choice for null is valid will always be returned.
 String getModelValue()
           
protected  Object getNoSelectionValue()
          In case "-1" is not a suitable "no selection value", you may provide your own implementation of getNoSelectionValue().
protected  String getNullKey()
          Return the localization key for null value
protected  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, 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, supportsPersistence
 
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, isPersistent, isRequired, isValid, newValidatable, onComponentTag, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setModelValue, setPersistent, setRequired, setType, shouldTrimInput, trim, 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
getMarkupType, getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setDefaultModel, setMarkupStream, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onConfigure, onEndRequest, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, 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
 

Field Detail

NO_SELECTION_VALUE

protected static final Object NO_SELECTION_VALUE
Constructor Detail

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id)
See Also:
AbstractChoice.AbstractChoice(String)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  List<? extends T> choices)
See Also:
AbstractChoice.AbstractChoice(String, List)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  List<? extends T> data,
                                  IChoiceRenderer<? super T> renderer)
Parameters:
id -
data -
renderer -
See Also:
AbstractChoice.AbstractChoice(String, List ,IChoiceRenderer)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<T> model,
                                  List<? extends T> data)
See Also:
AbstractChoice.AbstractChoice(String, IModel, List)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<T> model,
                                  List<? extends T> data,
                                  IChoiceRenderer<? super T> renderer)
Parameters:
id -
model -
data -
renderer -
See Also:
AbstractChoice.AbstractChoice(String, IModel, List, IChoiceRenderer)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<? extends List<? extends T>> choices)
See Also:
AbstractChoice.AbstractChoice(String, IModel)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<T> model,
                                  IModel<? extends List<? extends T>> choices)
See Also:
AbstractChoice.AbstractChoice(String, IModel,IModel)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<? extends List<? extends T>> choices,
                                  IChoiceRenderer<? super T> renderer)
See Also:
AbstractChoice.AbstractChoice(String, IModel,IChoiceRenderer)

AbstractSingleSelectChoice

public AbstractSingleSelectChoice(String id,
                                  IModel<T> model,
                                  IModel<? extends List<? extends T>> choices,
                                  IChoiceRenderer<? super T> renderer)
See Also:
AbstractChoice.AbstractChoice(String, IModel, IModel,IChoiceRenderer)
Method Detail

getNoSelectionValue

protected Object getNoSelectionValue()
In case "-1" is not a suitable "no selection value", you may provide your own implementation of getNoSelectionValue(). The return Object's toString() will be used as the "no selection value". Object.equals() must return true when equal. Thus besides special object, simply returning a String (e.g. "999") would be ok as well. By default NO_SELECTION_VALUE will be returned. By purpose there is no setter for the "no selection object". You should add the variable to your subclass.

Returns:
The "no selection object"

getModelValue

public 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(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(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 CharSequence getDefaultChoice(Object selected)
The localizer will be ask for the property to display Depending on if null is allowed or not it will ask for: The choice for null is valid will always be returned. The choice when null is not valid will only be returned if the selected object is null.

Overrides:
getDefaultChoice in class AbstractChoice<T,T>
Parameters:
selected - The object that's currently selected
Returns:
Any default choice, such as "Choose One", depending on the subclass
See Also:
AbstractChoice.getDefaultChoice(Object)

getNullValidKey

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

Returns:
getId() + ".nullValid"

getNullKey

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

Returns:
getId() + ".null"

isSelected

protected boolean isSelected(T object,
                             int index,
                             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 © 2004-2011 Apache Software Foundation. All Rights Reserved.