org.odlabs.wiquery.ui.autocomplete
Class Autocomplete<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.AbstractTextComponent<T>
                          extended by org.apache.wicket.markup.html.form.TextField<T>
                              extended by org.odlabs.wiquery.ui.autocomplete.Autocomplete<T>
Type Parameters:
T - The model object type
All Implemented Interfaces:
Serializable, Iterable<org.apache.wicket.Component>, org.apache.wicket.event.IEventSink, org.apache.wicket.event.IEventSource, org.apache.wicket.IClusterable, org.apache.wicket.IConverterLocator, org.apache.wicket.markup.html.form.IFormModelUpdateListener, org.apache.wicket.markup.html.form.IFormVisitorParticipant, org.apache.wicket.markup.html.form.ILabelProvider<String>, org.apache.wicket.markup.html.IHeaderContributor, org.apache.wicket.request.component.IRequestableComponent, org.apache.wicket.util.IHierarchical<org.apache.wicket.Component>, IWiQueryPlugin

public class Autocomplete<T>
extends org.apache.wicket.markup.html.form.TextField<T>
implements IWiQueryPlugin

$Id$

Creates an autocomplete UI component

Since:
1.1
Author:
Julien Roche
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.markup.html.form.AbstractTextComponent
org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider
 
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
Autocomplete(String id)
          Constructor
Autocomplete(String id, org.apache.wicket.model.IModel<T> model)
          Constructor
 
Method Summary
 JsStatement close()
          Method to close the autocomplete This will return the element back to its pre-init state.
 void close(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to close the autocomplete within the ajax request
 JsStatement destroy()
          Method to destroy the autocomplete This will return the element back to its pre-init state.
 void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to destroy the autocomplete within the ajax request
protected  void detachModel()
           
 JsStatement disable()
          Method to disable the autocomplete
 void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to disable the button within the ajax request
 JsStatement enable()
          Method to enable the autocomplete
 void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to enable the autocomplete within the ajax request
 String getAppendTo()
           
 int getDelay()
           
 int getMinLength()
           
protected  Options getOptions()
          Method retrieving the options of the component
 PositionOptions getPosition()
           
 AutocompleteSource getSource()
           
 boolean isDisabled()
           
 void renderHead(org.apache.wicket.markup.html.IHeaderResponse response)
           
 JsStatement search()
          Method to search the autocomplete
 void search(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to search the autocomplete within the ajax request
 void search(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget, String value)
          Method to search the autocomplete within the ajax request
 JsStatement search(String value)
          Method to search the autocomplete
 Autocomplete<T> setAppendTo(String appendTo)
          The element passed to or selected by the appendTo option will be used as the container for the suggested values
 Autocomplete<T> setChangeEvent(JsScopeUiEvent change)
          After an item was selected; ui.item refers to the selected item.
 Autocomplete<T> setCloseEvent(JsScopeUiEvent close)
          When the list is hidden - doesn't have to occur together with a change.
 Autocomplete<T> setDelay(int delay)
          The delay in milliseconds the autocomplete waits after a keystroke to activate itself.
 Autocomplete<T> setDisabled(boolean disabled)
          Disables (true) or enables (false) the autocomplete.
 Autocomplete<T> setFocusEvent(JsScopeUiEvent focus)
          Before focus is moved to an item (not selecting), ui.item refers to the focused item.
 Autocomplete<T> setMinLength(int minLength)
          The minimum number of characters a user has to type before the autocomplete activates.
 Autocomplete<T> setOpenEvent(JsScopeUiEvent open)
          After a request with the data ready, before it is actually displayed; also indicates the suggestion menu will be opened.
 Autocomplete<T> setPosition(PositionOptions position)
          Position of the component of the suggested values with the input field
 Autocomplete<T> setSearchEvent(JsScopeUiEvent search)
          Before a request (source-option) is started, after minLength and delay are met.
 Autocomplete<T> setSelectEvent(JsScopeUiEvent select)
          Triggered when an item is selected from the menu; ui.item refers to the selected item.
 Autocomplete<T> setSource(AutocompleteSource source)
          Defines the data to use, must be specified.
 JsStatement statement()
          Returns the main JsStatement used to create the plugin.
 JsStatement widget()
          Method to returns the .ui-autocomplete element
 void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to returns the .ui-autocomplete element within the ajax request
 
Methods inherited from class org.apache.wicket.markup.html.form.TextField
getInputType, onComponentTag
 
Methods inherited from class org.apache.wicket.markup.html.form.AbstractTextComponent
convertInput, getConvertEmptyInputStringToNull, isInputNullable, onBeforeRender, setConvertEmptyInputStringToNull
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, checkRequired, clearInput, convertValue, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInput, getInputAsArray, getInputName, getModel, getModelObject, getModelValue, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isMultiPart, isRequired, isValid, newValidatable, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, remove, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setRequired, setType, 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, onComponentTagBody, 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, 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, onConfigure, onEvent, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, 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, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Autocomplete

public Autocomplete(String id)
Constructor

Parameters:
id - Wicket identifiant

Autocomplete

public Autocomplete(String id,
                    org.apache.wicket.model.IModel<T> model)
Constructor

Parameters:
id - Wicket identifiant
model - Model
Method Detail

detachModel

protected void detachModel()
Overrides:
detachModel in class org.apache.wicket.Component

renderHead

public void renderHead(org.apache.wicket.markup.html.IHeaderResponse response)
Specified by:
renderHead in interface org.apache.wicket.markup.html.IHeaderContributor
Overrides:
renderHead in class org.apache.wicket.Component

getOptions

protected Options getOptions()
Method retrieving the options of the component

Returns:
the options

statement

public JsStatement statement()
Description copied from interface: IWiQueryPlugin
Returns the main JsStatement used to create the plugin.

Specified by:
statement in interface IWiQueryPlugin
Returns:
The JsStatement corresponding to this component.

setAppendTo

public Autocomplete<T> setAppendTo(String appendTo)
The element passed to or selected by the appendTo option will be used as the container for the suggested values

Parameters:
appendTo -
Returns:
instance of the current component

getAppendTo

public String getAppendTo()
Returns:
the appendTo option value

setDelay

public Autocomplete<T> setDelay(int delay)
The delay in milliseconds the autocomplete waits after a keystroke to activate itself. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive.

Parameters:
delay -
Returns:
instance of the current component

getDelay

public int getDelay()
Returns:
the delay option value

setMinLength

public Autocomplete<T> setMinLength(int minLength)
The minimum number of characters a user has to type before the autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.

Parameters:
minLength -
Returns:
instance of the current component

getMinLength

public int getMinLength()
Returns:
the delay option value

setPosition

public Autocomplete<T> setPosition(PositionOptions position)
Position of the component of the suggested values with the input field

Parameters:
position -
Returns:
instance of the current component

getPosition

public PositionOptions getPosition()
Returns:
the position option value

setSource

public Autocomplete<T> setSource(AutocompleteSource source)
Defines the data to use, must be specified. There are three variations: The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with a label or value property or both. The label property is displayed in the suggestion menu, the value will be inserted into the input element after the user selected something from the menu. If just one is specified, it will be used for both, eg. if you provide only value-properties, they will also be used as the label. When a String is used, the Autocomplete plugin expects that string to point to a resource to return JSON data. It can be on the same host or on a different one (must provide JSONP). The data itself can be in the same format as the local data described above. The third variation, the callback, provides the most flexibility, and can be used to connect any datasource to the Autocomplete. The callback gets two arguments:

Parameters:
source -
Returns:
instance of the current component

getSource

public AutocompleteSource getSource()
Returns:
the source option value

setDisabled

public Autocomplete<T> setDisabled(boolean disabled)
Disables (true) or enables (false) the autocomplete. Can be set when initialising (first creating) the autcomplete.

Parameters:
disabled -
Returns:
instance of the current behavior

isDisabled

public boolean isDisabled()
Returns:
the disabled option

setChangeEvent

public Autocomplete<T> setChangeEvent(JsScopeUiEvent change)
After an item was selected; ui.item refers to the selected item. Always triggered after the close event.

Parameters:
change -
Returns:
instance of the current component

setCloseEvent

public Autocomplete<T> setCloseEvent(JsScopeUiEvent close)
When the list is hidden - doesn't have to occur together with a change.

Parameters:
close -
Returns:
instance of the current component

setFocusEvent

public Autocomplete<T> setFocusEvent(JsScopeUiEvent focus)
Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item. Cancelling this event prevents the value from being updated, but does not prevent the menu item from being focused.

Parameters:
focus -
Returns:
instance of the current component

setOpenEvent

public Autocomplete<T> setOpenEvent(JsScopeUiEvent open)
After a request with the data ready, before it is actually displayed; also indicates the suggestion menu will be opened.

Parameters:
open -
Returns:
instance of the current component

setSearchEvent

public Autocomplete<T> setSearchEvent(JsScopeUiEvent search)
Before a request (source-option) is started, after minLength and delay are met. Can be cancelled (return false), then no request will be started and no items suggested.

Parameters:
search -
Returns:
instance of the current component

setSelectEvent

public Autocomplete<T> setSelectEvent(JsScopeUiEvent select)
Triggered when an item is selected from the menu; ui.item refers to the selected item. The default action of select is to replace the text field's value with the value of the selected item. Cancelling this event prevents the value from being updated, but does not prevent the menu from closing.

Parameters:
select -
Returns:
instance of the current component

close

public JsStatement close()
Method to close the autocomplete This will return the element back to its pre-init state.

Returns:
the associated JsStatement

close

public void close(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to close the autocomplete within the ajax request

Parameters:
ajaxRequestTarget -

destroy

public JsStatement destroy()
Method to destroy the autocomplete This will return the element back to its pre-init state.

Returns:
the associated JsStatement

destroy

public void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to destroy the autocomplete within the ajax request

Parameters:
ajaxRequestTarget -

disable

public JsStatement disable()
Method to disable the autocomplete

Returns:
the associated JsStatement

disable

public void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to disable the button within the ajax request

Parameters:
ajaxRequestTarget -

enable

public JsStatement enable()
Method to enable the autocomplete

Returns:
the associated JsStatement

enable

public void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to enable the autocomplete within the ajax request

Parameters:
ajaxRequestTarget -

search

public JsStatement search()
Method to search the autocomplete

Returns:
the associated JsStatement

search

public void search(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to search the autocomplete within the ajax request

Parameters:
ajaxRequestTarget -

search

public JsStatement search(String value)
Method to search the autocomplete

Parameters:
value - String
Returns:
the associated JsStatement

search

public void search(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget,
                   String value)
Method to search the autocomplete within the ajax request

Parameters:
ajaxRequestTarget -
value - String

widget

public JsStatement widget()
Method to returns the .ui-autocomplete element

Returns:
the associated JsStatement

widget

public void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to returns the .ui-autocomplete element within the ajax request

Parameters:
ajaxRequestTarget -


Copyright © 2012. All Rights Reserved.