Save This Page
Home » struts- » org.apache.struts2.dojo » components » [javadoc | source]
public class: Autocompleter [javadoc | source]

The autocomplete tag is a combobox that can autocomplete text entered on the input box. If an action is used to populate the autocompleter, the output of the action must be a well formed JSON string.

The autocompleter follows this rule to find its datasource:

1. If the response is an array, assume that it contains 2-dimension array elements, like:

     ["Alabama", "AL"],
     ["Alaska", "AK"]

2. If a value is specified in the "dataFieldName" attribute, and the response has a field with that name, assume that's the datasource, which can be an array of 2-dimension array elements, or a map, like (assuming dataFieldName="state"):

     "state" : [
     "state" : {
           "Alabama" : "AL",
           "Alaska" : "AK"

3. If there is a field that starts with the value specified on the "name" attribute, assume that's the datasource, like (assuming name="state"):

     "states" : [

4. Use first array that is found, like:

     "anything" : [
           ["Alabama", "AL"],
           ["Alaska", "AK"]

5. If the response is a map, use it (recommended as it is the easiest one to generate):

     "Alabama" : "AL",
     "Alaska" : "AK"


<sx:autocompleter name="autocompleter1" href="%{jsonList}"/> <s:autocompleter name="test" list="{'apple','banana','grape','pear'}" autoComplete="false"/> <sx:autocompleter name="mvc" href="%{jsonList}" loadOnTextChange="true" loadMinimumCount="3"/> The text entered on the autocompleter is passed as a parameter to the url specified in "href", like (text is "struts"): http://host/example/ <form id="selectForm"> <sx:autocompleter name="select" list="{'fruits','colors'}" valueNotifyTopics="/changed" /> </form> <sx:autocompleter href="%{jsonList}" formId="selectForm" listenTopics="/changed"/> <sx:autocompleter href="%{jsonList}" id="auto"/> <script type="text/javascript"> function getValues() { var autoCompleter = dojo.widget.byId("auto"); //key (in the states example above, "AL") var key = autoCompleter.getSelectedKey(); alert(key); //value (in the states example above, "Alabama") var value = autoCompleter.getSelectedValue(); alert(value); //text currently on the textbox (anything the user typed) var text = autoCompleter.getText(); alert(text); } function setValues() { var autoCompleter = dojo.widget.byId("auto"); //key (key will be set to "AL" and value to "Alabama") autoCompleter.setSelectedKey("AL"); //value (key will be set to "AL" and value to "Alabama") autoCompleter.setAllValues("AL", "Alabama"); } </script> <script type="text/javascript"> dojo.event.topic.subscribe("/before", function(event, widget){ alert('inside a topic event. before request'); //event: set event.cancel = true, to cancel request //widget: widget that published the topic }); </script> <sx:autocompleter beforeNotifyTopics="/before" href="%{#ajaxTest} /> <script type="text/javascript"> dojo.event.topic.subscribe("/after", function(data, request, widget){ alert('inside a topic event. after request'); //data : JavaScript object from parsing response //request: XMLHttpRequest object //widget: widget that published the topic }); </script> <sx:autocompleter afterNotifyTopics="/after" href="%{#ajaxTest}" /> <script type="text/javascript"> dojo.event.topic.subscribe("/error", function(error, request, widget){ alert('inside a topic event. on error'); //error : error object (error.message has the error message) //request: XMLHttpRequest object //widget: widget that published the topic }); </script> <sx:autocompleter errorNotifyTopics="/error" href="%{#ajaxTest}" /> <script type="text/javascript"> dojo.event.topic.subscribe("/value", function(value, key, text, widget){ alert('inside a topic event. after value changed'); //value : selected value (like "Florida" in example above) //key: selected key (like "FL" in example above) //text: text typed into textbox //widget: widget that published the topic }); </script> <sx:autocompleter valueNotifyTopics="/value" href="%{#ajaxTest}" />
Field Summary
public static final  String TEMPLATE     
protected  String forceValidOption     
protected  String searchType     
protected  String autoComplete     
protected  String delay     
protected  String disabled     
protected  String href     
protected  String dropdownWidth     
protected  String dropdownHeight     
protected  String formId     
protected  String formFilter     
protected  String listenTopics     
protected  String notifyTopics     
protected  String indicator     
protected  String loadOnTextChange     
protected  String loadMinimumCount     
protected  String showDownArrow     
protected  String templateCssPath     
protected  String iconPath     
protected  String keyName     
protected  String dataFieldName     
protected  String beforeNotifyTopics     
protected  String afterNotifyTopics     
protected  String errorNotifyTopics     
protected  String valueNotifyTopics     
protected  String resultsLimit     
protected  String transport     
protected  String preload     
protected  String keyValue     
Fields inherited from org.apache.struts2.components.ComboBox:
TEMPLATE,  list,  listKey,  listValue,  headerKey,  headerValue,  emptyOption
Fields inherited from org.apache.struts2.components.TextField:
TEMPLATE,  maxlength,  readonly,  size
Fields inherited from org.apache.struts2.components.UIBean:
request,  response,  templateSuffix,  template,  templateDir,  theme,  key,  id,  cssClass,  cssStyle,  cssErrorClass,  cssErrorStyle,  disabled,  label,  labelPosition,  labelSeparator,  requiredposition,  name,  required,  tabindex,  value,  title,  onclick,  ondblclick,  onmousedown,  onmouseup,  onmouseover,  onmousemove,  onmouseout,  onfocus,  onblur,  onkeypress,  onkeydown,  onkeyup,  onselect,  onchange,  accesskey,  tooltip,  tooltipConfig,  javascriptTooltip,  tooltipDelay,  tooltipCssClass,  tooltipIconPath,  dynamicAttributes,  defaultTemplateDir,  defaultUITheme,  templateEngineManager
Fields inherited from org.apache.struts2.components.Component:
COMPONENT_STACK,  stack,  parameters,  actionMapper,  throwExceptionOnELFailure
 public Autocompleter(ValueStack stack,
    HttpServletRequest request,
    HttpServletResponse response) 
Method from org.apache.struts2.dojo.components.Autocompleter Summary:
evaluateExtraParams,   findListValue,   getComponentName,   getDefaultTemplate,   getTheme,   setAfterNotifyTopics,   setAutoComplete,   setBeforeNotifyTopics,   setCssClass,   setCssStyle,   setDataFieldName,   setDelay,   setDisabled,   setDropdownHeight,   setDropdownWidth,   setErrorNotifyTopics,   setForceValidOption,   setFormFilter,   setFormId,   setHref,   setIconPath,   setId,   setIndicator,   setKeyName,   setKeyValue,   setList,   setListenTopics,   setLoadMinimumCount,   setLoadOnTextChange,   setName,   setNotifyTopics,   setPreload,   setResultsLimit,   setSearchType,   setShowDownArrow,   setTemplateCssPath,   setTheme,   setTransport,   setValue,   setValueNotifyTopics
Methods from org.apache.struts2.components.ComboBox:
evaluateExtraParams,   findListValue,   getDefaultTemplate,   setEmptyOption,   setHeaderKey,   setHeaderValue,   setList,   setListKey,   setListValue
Methods from org.apache.struts2.components.TextField:
evaluateExtraParams,   getDefaultTemplate,   setMaxLength,   setMaxlength,   setReadonly,   setSize
Methods from org.apache.struts2.components.UIBean:
addFormParameter,   buildTemplateName,   enableAncestorFormCustomOnsubmit,   end,   ensureAttributeSafelyNotEscaped,   escape,   evaluateExtraParams,   evaluateNameValue,   evaluateParams,   getDefaultTemplate,   getId,   getTemplate,   getTemplateDir,   getTheme,   getTooltipConfig,   getValueClassType,   mergeTemplate,   populateComponentHtmlId,   setAccesskey,   setCssClass,   setCssErrorClass,   setCssErrorStyle,   setCssStyle,   setDefaultTemplateDir,   setDefaultUITheme,   setDisabled,   setDynamicAttributes,   setId,   setJavascriptTooltip,   setKey,   setLabel,   setLabelSeparator,   setLabelposition,   setName,   setOnblur,   setOnchange,   setOnclick,   setOndblclick,   setOnfocus,   setOnkeydown,   setOnkeypress,   setOnkeyup,   setOnmousedown,   setOnmousemove,   setOnmouseout,   setOnmouseover,   setOnmouseup,   setOnselect,   setRequired,   setRequiredposition,   setTabindex,   setTemplate,   setTemplateDir,   setTemplateEngineManager,   setTheme,   setTitle,   setTooltip,   setTooltipConfig,   setTooltipCssClass,   setTooltipDelay,   setTooltipIconPath,   setValue
Methods from org.apache.struts2.components.Component:
addAllParameters,   addParameter,   altSyntax,   altSyntax,   completeExpressionIfAltSyntax,   copyParams,   determineActionURL,   determineNamespace,   end,   end,   fieldError,   findAncestor,   findString,   findString,   findStringIfAltSyntax,   findValue,   findValue,   findValue,   getComponentStack,   getParameters,   getStack,   popComponentStack,   setActionMapper,   setThrowExceptionsOnELFailure,   start,   stripExpressionIfAltSyntax,   stripExpressionIfAltSyntax,   toString,   usesBody
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts2.dojo.components.Autocompleter Detail:
 public  void evaluateExtraParams() 
 protected Object findListValue() 
 public String getComponentName() 
 protected String getDefaultTemplate() 
 public String getTheme() 
 public  void setAfterNotifyTopics(String afterNotifyTopics) 
 public  void setAutoComplete(String autoComplete) 
 public  void setBeforeNotifyTopics(String beforeNotifyTopics) 
 public  void setCssClass(String cssClass) 
 public  void setCssStyle(String cssStyle) 
 public  void setDataFieldName(String dataFieldName) 
 public  void setDelay(String searchDelay) 
 public  void setDisabled(String disabled) 
 public  void setDropdownHeight(String height) 
 public  void setDropdownWidth(String width) 
 public  void setErrorNotifyTopics(String errorNotifyTopics) 
 public  void setForceValidOption(String forceValidOption) 
 public  void setFormFilter(String formFilter) 
 public  void setFormId(String formId) 
 public  void setHref(String href) 
 public  void setIconPath(String iconPath) 
 public  void setId(String id) 
 public  void setIndicator(String indicator) 
 public  void setKeyName(String keyName) 
 public  void setKeyValue(String keyValue) 
 public  void setList(String list) 
 public  void setListenTopics(String listenTopics) 
 public  void setLoadMinimumCount(String loadMinimumCount) 
 public  void setLoadOnTextChange(String loadOnType) 
 public  void setName(String name) 
 public  void setNotifyTopics(String onValueChangedPublishTopic) 
 public  void setPreload(String preload) 
 public  void setResultsLimit(String resultsLimit) 
 public  void setSearchType(String searchType) 
 public  void setShowDownArrow(String showDownArrow) 
 public  void setTemplateCssPath(String templateCssPath) 
 public  void setTheme(String theme) 
 public  void setTransport(String transport) 
 public  void setValue(String arg0) 
 public  void setValueNotifyTopics(String valueNotifyTopics)