org.apache.struts2.dojo.components
Class Autocompleter

java.lang.Object
  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.UIBean
          extended by org.apache.struts2.components.TextField
              extended by org.apache.struts2.components.ComboBox
                  extended by org.apache.struts2.dojo.components.Autocompleter

public class Autocompleter
extends ComboBox

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" : [
           ["Alabama","AL"],
           ["Alaska","AK"]
      ]
 }     
 or
 {
      "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" : [
           ["Alabama","AL"],
           ["Alaska","AK"]
      ]
 }
 

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"
 }
 

Examples

<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/myaction.do?mvc=struts <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
protected  String afterNotifyTopics
           
protected  String autoComplete
           
protected  String beforeNotifyTopics
           
protected  String dataFieldName
           
protected  String delay
           
protected  String disabled
           
protected  String dropdownHeight
           
protected  String dropdownWidth
           
protected  String errorNotifyTopics
           
protected  String forceValidOption
           
protected  String formFilter
           
protected  String formId
           
protected  String href
           
protected  String iconPath
           
protected  String indicator
           
protected  String keyName
           
protected  String keyValue
           
protected  String listenTopics
           
protected  String loadMinimumCount
           
protected  String loadOnTextChange
           
protected  String notifyTopics
           
protected  String preload
           
protected  String resultsLimit
           
protected  String searchType
           
protected  String showDownArrow
           
static String TEMPLATE
           
protected  String templateCssPath
           
protected  String transport
           
protected  String valueNotifyTopics
           
 
Fields inherited from class org.apache.struts2.components.ComboBox
emptyOption, headerKey, headerValue, list, listKey, listValue
 
Fields inherited from class org.apache.struts2.components.TextField
maxlength, readonly, size, type
 
Fields inherited from class org.apache.struts2.components.UIBean
accesskey, cssClass, cssErrorClass, cssErrorStyle, cssStyle, defaultTemplateDir, defaultUITheme, dynamicAttributes, id, javascriptTooltip, key, label, labelPosition, labelSeparator, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onselect, request, required, requiredposition, response, standardAttributesMap, tabindex, template, templateDir, templateEngineManager, templateSuffix, theme, title, tooltip, tooltipConfig, tooltipCssClass, tooltipDelay, tooltipIconPath, value
 
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, parameters, stack, throwExceptionOnELFailure
 
Constructor Summary
Autocompleter(com.opensymphony.xwork2.util.ValueStack stack, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 
Method Summary
 void evaluateExtraParams()
           
protected  Object findListValue()
           
 String getComponentName()
           
protected  String getDefaultTemplate()
           
 String getTheme()
           
 void setAfterNotifyTopics(String afterNotifyTopics)
           
 void setAutoComplete(String autoComplete)
           
 void setBeforeNotifyTopics(String beforeNotifyTopics)
           
 void setCssClass(String cssClass)
           
 void setCssStyle(String cssStyle)
           
 void setDataFieldName(String dataFieldName)
           
 void setDelay(String searchDelay)
           
 void setDisabled(String disabled)
           
 void setDropdownHeight(String height)
           
 void setDropdownWidth(String width)
           
 void setErrorNotifyTopics(String errorNotifyTopics)
           
 void setForceValidOption(String forceValidOption)
           
 void setFormFilter(String formFilter)
           
 void setFormId(String formId)
           
 void setHref(String href)
           
 void setIconPath(String iconPath)
           
 void setId(String id)
           
 void setIndicator(String indicator)
           
 void setKeyName(String keyName)
           
 void setKeyValue(String keyValue)
           
 void setList(String list)
           
 void setListenTopics(String listenTopics)
           
 void setLoadMinimumCount(String loadMinimumCount)
           
 void setLoadOnTextChange(String loadOnType)
           
 void setName(String name)
           
 void setNotifyTopics(String onValueChangedPublishTopic)
           
 void setPreload(String preload)
           
 void setResultsLimit(String resultsLimit)
           
 void setSearchType(String searchType)
           
 void setShowDownArrow(String showDownArrow)
           
 void setTemplateCssPath(String templateCssPath)
           
 void setTheme(String theme)
           
 void setTransport(String transport)
           
 void setValue(String arg0)
           
 void setValueNotifyTopics(String valueNotifyTopics)
           
 
Methods inherited from class org.apache.struts2.components.ComboBox
setEmptyOption, setHeaderKey, setHeaderValue, setListKey, setListValue
 
Methods inherited from class org.apache.struts2.components.TextField
setMaxlength, setMaxLength, setReadonly, setSize, setType
 
Methods inherited from class org.apache.struts2.components.UIBean
addFormParameter, buildTemplateName, copyParams, enableAncestorFormCustomOnsubmit, end, ensureAttributeSafelyNotEscaped, escape, evaluateNameValue, evaluateParams, getId, getStandardAttributes, getTemplate, getTemplateDir, getTooltipConfig, getValueClassType, mergeTemplate, populateComponentHtmlId, setAccesskey, setCssErrorClass, setCssErrorStyle, setDefaultTemplateDir, setDefaultUITheme, setDynamicAttributes, setJavascriptTooltip, setKey, setLabel, setLabelposition, setLabelSeparator, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setRequired, setRequiredposition, setTabindex, setTemplate, setTemplateDir, setTemplateEngineManager, setTitle, setTooltip, setTooltipConfig, setTooltipCssClass, setTooltipDelay, setTooltipIconPath
 
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, addParameter, altSyntax, completeExpressionIfAltSyntax, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findStringIfAltSyntax, findValue, findValue, findValue, getComponentStack, getParameters, getStack, popComponentStack, setActionMapper, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpressionIfAltSyntax, toString, usesBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE

public static final String TEMPLATE
See Also:
Constant Field Values

forceValidOption

protected String forceValidOption

searchType

protected String searchType

autoComplete

protected String autoComplete

delay

protected String delay

disabled

protected String disabled

href

protected String href

dropdownWidth

protected String dropdownWidth

dropdownHeight

protected String dropdownHeight

formId

protected String formId

formFilter

protected String formFilter

listenTopics

protected String listenTopics

notifyTopics

protected String notifyTopics

indicator

protected String indicator

loadOnTextChange

protected String loadOnTextChange

loadMinimumCount

protected String loadMinimumCount

showDownArrow

protected String showDownArrow

templateCssPath

protected String templateCssPath

iconPath

protected String iconPath

keyName

protected String keyName

dataFieldName

protected String dataFieldName

beforeNotifyTopics

protected String beforeNotifyTopics

afterNotifyTopics

protected String afterNotifyTopics

errorNotifyTopics

protected String errorNotifyTopics

valueNotifyTopics

protected String valueNotifyTopics

resultsLimit

protected String resultsLimit

transport

protected String transport

preload

protected String preload

keyValue

protected String keyValue
Constructor Detail

Autocompleter

public Autocompleter(com.opensymphony.xwork2.util.ValueStack stack,
                     javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
Method Detail

getDefaultTemplate

protected String getDefaultTemplate()
Overrides:
getDefaultTemplate in class ComboBox

getComponentName

public String getComponentName()

evaluateExtraParams

public void evaluateExtraParams()
Overrides:
evaluateExtraParams in class ComboBox

setTheme

public void setTheme(String theme)
Overrides:
setTheme in class UIBean

getTheme

public String getTheme()
Overrides:
getTheme in class UIBean

findListValue

protected Object findListValue()
Overrides:
findListValue in class ComboBox

setAutoComplete

public void setAutoComplete(String autoComplete)

setDisabled

public void setDisabled(String disabled)
Overrides:
setDisabled in class UIBean

setForceValidOption

public void setForceValidOption(String forceValidOption)

setHref

public void setHref(String href)

setDelay

public void setDelay(String searchDelay)

setSearchType

public void setSearchType(String searchType)

setDropdownHeight

public void setDropdownHeight(String height)

setDropdownWidth

public void setDropdownWidth(String width)

setFormFilter

public void setFormFilter(String formFilter)

setFormId

public void setFormId(String formId)

setListenTopics

public void setListenTopics(String listenTopics)

setNotifyTopics

public void setNotifyTopics(String onValueChangedPublishTopic)

setIndicator

public void setIndicator(String indicator)

setLoadMinimumCount

public void setLoadMinimumCount(String loadMinimumCount)

setLoadOnTextChange

public void setLoadOnTextChange(String loadOnType)

setShowDownArrow

public void setShowDownArrow(String showDownArrow)

setList

public void setList(String list)
Overrides:
setList in class ComboBox

setTemplateCssPath

public void setTemplateCssPath(String templateCssPath)

setIconPath

public void setIconPath(String iconPath)

setKeyName

public void setKeyName(String keyName)

setDataFieldName

public void setDataFieldName(String dataFieldName)

setCssClass

public void setCssClass(String cssClass)
Overrides:
setCssClass in class UIBean

setCssStyle

public void setCssStyle(String cssStyle)
Overrides:
setCssStyle in class UIBean

setId

public void setId(String id)
Overrides:
setId in class UIBean

setName

public void setName(String name)
Overrides:
setName in class UIBean

setValue

public void setValue(String arg0)
Overrides:
setValue in class UIBean

setAfterNotifyTopics

public void setAfterNotifyTopics(String afterNotifyTopics)

setBeforeNotifyTopics

public void setBeforeNotifyTopics(String beforeNotifyTopics)

setErrorNotifyTopics

public void setErrorNotifyTopics(String errorNotifyTopics)

setValueNotifyTopics

public void setValueNotifyTopics(String valueNotifyTopics)

setResultsLimit

public void setResultsLimit(String resultsLimit)

setTransport

public void setTransport(String transport)

setPreload

public void setPreload(String preload)

setKeyValue

public void setKeyValue(String keyValue)


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.