com.databasesandlife.util.wicket
Class MultipleValueAutoSuggestTextField

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.FormComponentPanel<String[]>
                          extended by com.databasesandlife.util.wicket.MultipleValueAutoSuggestTextField
All Implemented Interfaces:
Serializable, IClusterable, IConverterLocator, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderPartContainerProvider

public class MultipleValueAutoSuggestTextField
extends FormComponentPanel<String[]>

Represents a text-field in Wicket, which allows the user to enter multiple values, and values are suggested from a list of existing values. These values are only suggestions, however, the user may type in other new values, not in the list of existing values. This is ideal for entering tags on a newly created object, where you want the user to use existing tags if appropriate, but also allow the user to create new tags if none of the existing ones are appropriate.

    

If new values should not be allowed, for example when selecting from a list of existing languages, see MultipleValueAutoCompleteTextField.

The model of the field is an array of Strings which have been chosen. (It is not possible to display strings to the user, while maintaining a list of IDs corresponding to those strings internally, as the user may enter new strings, and those would have no corresponding IDs.)

The list of values to be suggested is a collection of Strings. There are two ways the these may be fetched:

Usage:

  <!-- in HTML -->
  <input type="text" wicket:id="tags" class="my-css-class"></input>

  // In Java
  MultipleValueAutoSuggestTextField tagsField =
      new MultipleValueAutoSuggestTextField("tags");
  tagsField.setClientSideOptions(new String[] { "java", "php" }); // or..
  tagsField.setServerSideDataSource(new AutoSuggestDataSource() {
      public String[] suggest(String userEnteredPartialText) {
          return new String[] { "java", "php" };
      }
  });
  form.add(tagsField);

If there is an error about a missing </span> tag, make sure the <input> tag is closed with a </input>, even though HTML would not normally require it to be closed. This is a consequence of an implementation issue.

The Javascript used by this software is based on the JQuery autocomplete multiple example.

Version:
$Revision: 2662 $
Author:
The Java source is copyright Adrian Smith and licensed under the LGPL 3.
See Also:
Serialized Form

Nested Class Summary
static interface MultipleValueAutoSuggestTextField.AutoSuggestDataSource
           
 
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
 
Field Summary
 
Fields inherited from class org.apache.wicket.markup.html.form.FormComponent
VALUE_SEPARATOR
 
Fields inherited from class org.apache.wicket.Component
ENABLE, PATH_SEPARATOR, RENDER
 
Constructor Summary
MultipleValueAutoSuggestTextField(String wicketId)
           
 
Method Summary
 String getCallInitializerJS()
          Internal method - Do not use
 MultipleValueAutoSuggestTextField setClientSideOptions(String[] options)
           
 MultipleValueAutoSuggestTextField setSeparator(String separatorForOutput, String separatorCharacterClassRegexp)
          When the user types multiple options, they will be separated by, for example, ",".
 MultipleValueAutoSuggestTextField setServerSideDataSource(MultipleValueAutoSuggestTextField.AutoSuggestDataSource dataSource)
           
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponentPanel
checkRequired, newHeaderPartContainer, renderHead
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, clearInput, error, getConvertedInput, getForm, getInput, getInputAsArray, getInputName, getModel, getModelObject, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputChanged, invalid, isInputNullable, isMultiPart, isPersistent, isRequired, isValid, newValidatable, processChildren, processInput, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setModelValue, setPersistent, setRequired, setType, updateModel, valid, validate, visitComponentsPostOrder, visitFormComponentsPostOrder
 
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel
 
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, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, remove, remove, removeAll, renderAssociatedMarkup, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, afterRender, beforeRender, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModels, determineVisibility, error, fatal, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getId, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, internalAttach, internalDetach, isActionAuthorized, isAncestorOf, isEnableAllowed, isEnabled, isEnabledInHierarchy, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, rendered, replaceWith, sameInnermostModel, sameInnermostModel, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultipleValueAutoSuggestTextField

public MultipleValueAutoSuggestTextField(String wicketId)
Method Detail

setClientSideOptions

public MultipleValueAutoSuggestTextField setClientSideOptions(String[] options)
Returns:
this

setServerSideDataSource

public MultipleValueAutoSuggestTextField setServerSideDataSource(MultipleValueAutoSuggestTextField.AutoSuggestDataSource dataSource)
Returns:
this

setSeparator

public MultipleValueAutoSuggestTextField setSeparator(String separatorForOutput,
                                                      String separatorCharacterClassRegexp)
When the user types multiple options, they will be separated by, for example, ",". This method sets that separator.

There are two places the separator is used: when generating the text field from a list of values (separatorForOutput), and when the text field is being parsed into a list of values (separatorCharacterClassRegexp, which is a regular expression).

Parameters:
separatorForOutput - For example ", " - plain text
separatorCharacterClassRegexp - For example ",;\\s" - regular expression
Returns:
this

getCallInitializerJS

public String getCallInitializerJS()
Internal method - Do not use