org.apache.wicket.markup.html.form
Class DropDownChoice

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
                      extended by org.apache.wicket.markup.html.form.AbstractSingleSelectChoice
                          extended by org.apache.wicket.markup.html.form.DropDownChoice
All Implemented Interfaces:
java.io.Serializable, IClusterable, IConverterLocator, IRequestListener, IFormVisitorParticipant, ILabelProvider, IOnChangeListener
Direct Known Subclasses:
ListChoice

public class DropDownChoice
extends AbstractSingleSelectChoice
implements IOnChangeListener

A choice implemented as a dropdown menu/list.

Java:

 List SITES = Arrays.asList(new String[] { "The Server Side", "Java Lobby", "Java.Net" });
 
 // Add a dropdown choice component that uses Input's 'site' property to designate the
 // current selection, and that uses the SITES list for the available options.
 // Note that when the selection is null, Wicket will lookup a localized string to
 // represent this null with key: "id + '.null'". In this case, this is 'site.null'
 // which can be found in DropDownChoicePage.properties
 form.add(new DropDownChoice("site", SITES));
 
HTML:
        <select wicket:id="site">
                <option>site 1</option>
                <option>site 2</option>
        </select>
 

You can can extend this class and override method wantOnSelectionChangedNotifications() to force server roundtrips on each selection change.

Author:
Jonathan Locke, Eelco Hillenius, 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
 
Fields inherited from class org.apache.wicket.markup.html.form.AbstractSingleSelectChoice
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_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Fields inherited from interface org.apache.wicket.markup.html.form.IOnChangeListener
INTERFACE
 
Constructor Summary
DropDownChoice(java.lang.String id)
           
DropDownChoice(java.lang.String id, IModel choices)
           
DropDownChoice(java.lang.String id, IModel choices, IChoiceRenderer renderer)
           
DropDownChoice(java.lang.String id, IModel model, IModel choices)
           
DropDownChoice(java.lang.String id, IModel model, IModel choices, IChoiceRenderer renderer)
           
DropDownChoice(java.lang.String id, IModel model, java.util.List choices)
           
DropDownChoice(java.lang.String id, IModel model, java.util.List data, IChoiceRenderer renderer)
           
DropDownChoice(java.lang.String id, java.util.List choices)
           
DropDownChoice(java.lang.String id, java.util.List data, IChoiceRenderer renderer)
           
 
Method Summary
protected  void appendOptionHtml(AppendingStringBuffer buffer, java.lang.Object choice, int index, java.lang.String selected)
          Generates and appends html for a single choice into the provided buffer
protected  void detachModel()
          Detaches the model for this component if it is detachable.
protected  java.lang.CharSequence escapeOptionHtml(java.lang.String displayValue)
          Method to override if you want special escaping of the options html.
 IChoiceRenderer getChoiceRenderer()
           
 java.util.List getChoices()
           
protected  boolean getStatelessHint()
          Returns whether the component can be stateless.
protected  boolean isDisabled(java.lang.Object object, int index, java.lang.String selected)
          Gets whether the given value is disabled.
protected  boolean localizeDisplayValues()
          Override this method if you want to localize the display values of the generated options.
protected  void onComponentTag(ComponentTag tag)
          Processes the component tag.
protected  void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
          Handle the container's body.
 void onSelectionChanged()
          Called when a selection changes.
protected  void onSelectionChanged(java.lang.Object newSelection)
          Template method that can be overridden by clients that implement IOnChangeListener to be notified by onChange events of a select element.
 org.apache.wicket.markup.html.form.AbstractChoice setChoiceRenderer(IChoiceRenderer renderer)
          Set the choice renderer to be used.
 org.apache.wicket.markup.html.form.AbstractChoice setChoices(IModel choices)
          Sets the list of choices
 org.apache.wicket.markup.html.form.AbstractChoice setChoices(java.util.List choices)
          Sets the list of choices.
protected  boolean supportsPersistence()
           
protected  boolean wantOnSelectionChangedNotifications()
          Whether this component's onSelectionChanged event handler should be called using javascript window.location if the selection changes.
 
Methods inherited from class org.apache.wicket.markup.html.form.AbstractSingleSelectChoice
convertChoiceIdToChoice, convertValue, getDefaultChoice, getModelValue, isNullValid, isSelected, setNullValid
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, checkRequired, clearInput, convertInput, error, getBehaviors, getConvertedInput, getForm, getInput, getInputAsArray, getInputName, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isMultiPart, isPersistent, isRequired, isValid, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, setConvertedInput, setLabel, setModelValue, setModelValue, setPersistent, setRequired, setType, shouldTrimInput, trim, updateModel, valid, validate, validateRequired, validateValidators, 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
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, continueToOriginalDestination, debug, detach, detachBehaviors, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getModelObjectAsString, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onEndRequest, onModelChanged, onModelChanging, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderHead, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMetaData, setModelObject, 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
 

Constructor Detail

DropDownChoice

public DropDownChoice(java.lang.String id)
See Also:
AbstractChoice.AbstractChoice(String)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      java.util.List choices)
See Also:
AbstractChoice.AbstractChoice(String, List)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      java.util.List data,
                      IChoiceRenderer renderer)
See Also:
AbstractChoice.AbstractChoice(String, List,IChoiceRenderer)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel model,
                      java.util.List choices)
See Also:
AbstractChoice.AbstractChoice(String, IModel, List)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel model,
                      java.util.List data,
                      IChoiceRenderer renderer)
See Also:
AbstractChoice.AbstractChoice(String, IModel, List, IChoiceRenderer)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel choices)
See Also:
AbstractChoice.AbstractChoice(String, IModel)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel model,
                      IModel choices)
See Also:
AbstractChoice.AbstractChoice(String, IModel,IModel)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel choices,
                      IChoiceRenderer renderer)
See Also:
AbstractChoice.AbstractChoice(String, IModel,IChoiceRenderer)

DropDownChoice

public DropDownChoice(java.lang.String id,
                      IModel model,
                      IModel choices,
                      IChoiceRenderer renderer)
See Also:
AbstractChoice.AbstractChoice(String, IModel, IModel,IChoiceRenderer)
Method Detail

onSelectionChanged

public final void onSelectionChanged()
Called when a selection changes.

Specified by:
onSelectionChanged in interface IOnChangeListener

onComponentTag

protected void onComponentTag(ComponentTag tag)
Processes the component tag.

Overrides:
onComponentTag in class FormComponent
Parameters:
tag - Tag to modify
See Also:
Component.onComponentTag(org.apache.wicket.markup.ComponentTag)

onSelectionChanged

protected void onSelectionChanged(java.lang.Object newSelection)
Template method that can be overridden by clients that implement IOnChangeListener to be notified by onChange events of a select element. This method does nothing by default.

Called when a option is selected of a dropdown list that wants to be notified of this event. This method is to be implemented by clients that want to be notified of selection events.

Parameters:
newSelection - The newly selected object of the backing model NOTE this is the same as you would get by calling getModelObject() if the new selection were current

wantOnSelectionChangedNotifications

protected boolean wantOnSelectionChangedNotifications()
Whether this component's onSelectionChanged event handler should be called using javascript window.location if the selection changes. If true, a roundtrip will be generated with each selection change, resulting in the model being updated (of just this component) and onSelectionChanged being called. This method returns false by default. If you wish to use Ajax instead, let wantOnSelectionChangedNotifications() return false and add an AjaxFormComponentUpdatingBehavior to the component using the onchange event.

Returns:
True if this component's onSelectionChanged event handler should called using javascript if the selection changes

getStatelessHint

protected boolean getStatelessHint()
Description copied from class: Component
Returns whether the component can be stateless. Also the component behaviors must be stateless, otherwise the component will be treat as stateful. In order for page to be stateless (and not to be stored in session), all components (and component behaviors) must be stateless.

Overrides:
getStatelessHint in class Component
Returns:
whether the component can be stateless
See Also:
Component.getStatelessHint()

getChoices

public java.util.List getChoices()
Returns:
The collection of object that this choice has

setChoices

public final org.apache.wicket.markup.html.form.AbstractChoice setChoices(IModel choices)
Sets the list of choices

Parameters:
choices - model representing the list of choices
Returns:
this for chaining

setChoices

public final org.apache.wicket.markup.html.form.AbstractChoice setChoices(java.util.List choices)
Sets the list of choices.

Parameters:
choices - the list of choices
Returns:
this for chaining

getChoiceRenderer

public final IChoiceRenderer getChoiceRenderer()
Returns:
The IChoiceRenderer used for rendering the data objects

setChoiceRenderer

public final org.apache.wicket.markup.html.form.AbstractChoice setChoiceRenderer(IChoiceRenderer renderer)
Set the choice renderer to be used.

Parameters:
renderer -
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 class Component
See Also:
Component.detachModel()

isDisabled

protected boolean isDisabled(java.lang.Object object,
                             int index,
                             java.lang.String selected)
Gets whether the given value is disabled. This default implementation always returns false.

Parameters:
object - The object to check
index - 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

protected void onComponentTagBody(MarkupStream markupStream,
                                  ComponentTag openTag)
Handle the container's body.

Overrides:
onComponentTagBody in class MarkupContainer
Parameters:
markupStream - The markup stream
openTag - The open tag for the body
See Also:
Component.onComponentTagBody(MarkupStream, ComponentTag)

appendOptionHtml

protected void appendOptionHtml(AppendingStringBuffer buffer,
                                java.lang.Object choice,
                                int index,
                                java.lang.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 appended
choice - Choice object
index - The index of this option
selected - The currently selected string value

escapeOptionHtml

protected java.lang.CharSequence escapeOptionHtml(java.lang.String displayValue)
Method to override if you want special escaping of the options html.

Parameters:
displayValue -
Returns:
The escaped display value

supportsPersistence

protected boolean supportsPersistence()
Overrides:
supportsPersistence in class FormComponent
Returns:
True if this type of FormComponent can be persisted.
See Also:
FormComponent.supportsPersistence()

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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.