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}" />
Modifier and Type | Field and Description |
---|---|
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 |
emptyOption, headerKey, headerValue, list, listKey, listValue
accesskey, cssClass, cssErrorClass, cssErrorStyle, cssStyle, defaultTemplateDir, defaultUITheme, dynamicAttributes, errorPosition, id, javascriptTooltip, key, label, labelPosition, labelSeparator, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onselect, request, requiredLabel, requiredPosition, response, standardAttributesMap, tabindex, template, templateDir, templateEngineManager, templateSuffix, theme, title, tooltip, tooltipConfig, tooltipCssClass, tooltipDelay, tooltipIconPath, uiThemeExpansionToken, value
actionMapper, COMPONENT_STACK, parameters, stack, throwExceptionOnELFailure
Constructor and Description |
---|
Autocompleter(com.opensymphony.xwork2.util.ValueStack stack,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
setEmptyOption, setHeaderKey, setHeaderValue, setListKey, setListValue
setMaxlength, setMaxLength, setReadonly, setSize, setType
addFormParameter, buildTemplateName, copyParams, enableAncestorFormCustomOnsubmit, end, ensureAttributeSafelyNotEscaped, escape, evaluateNameValue, evaluateParams, getId, getStandardAttributes, getTemplate, getTemplateDir, getTooltipConfig, getValueClassType, mergeTemplate, populateComponentHtmlId, setAccesskey, setCssErrorClass, setCssErrorStyle, setDefaultTemplateDir, setDefaultUITheme, setDynamicAttributes, setErrorPosition, setJavascriptTooltip, setKey, setLabel, setLabelposition, setLabelSeparator, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setRequiredLabel, setRequiredPosition, setTabindex, setTemplate, setTemplateDir, setTemplateEngineManager, setTitle, setTooltip, setTooltipConfig, setTooltipCssClass, setTooltipDelay, setTooltipIconPath, setUIThemeExpansionToken
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
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
public Autocompleter(com.opensymphony.xwork2.util.ValueStack stack, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected String getDefaultTemplate()
getDefaultTemplate
in class ComboBox
public String getComponentName()
public void evaluateExtraParams()
evaluateExtraParams
in class ComboBox
protected Object findListValue()
findListValue
in class ComboBox
public void setAutoComplete(String autoComplete)
public void setDisabled(String disabled)
setDisabled
in class UIBean
public void setForceValidOption(String forceValidOption)
public void setHref(String href)
public void setDelay(String searchDelay)
public void setSearchType(String searchType)
public void setDropdownHeight(String height)
public void setDropdownWidth(String width)
public void setFormFilter(String formFilter)
public void setFormId(String formId)
public void setListenTopics(String listenTopics)
public void setNotifyTopics(String onValueChangedPublishTopic)
public void setIndicator(String indicator)
public void setLoadMinimumCount(String loadMinimumCount)
public void setLoadOnTextChange(String loadOnType)
public void setShowDownArrow(String showDownArrow)
public void setTemplateCssPath(String templateCssPath)
public void setIconPath(String iconPath)
public void setKeyName(String keyName)
public void setDataFieldName(String dataFieldName)
public void setCssClass(String cssClass)
setCssClass
in class UIBean
public void setCssStyle(String cssStyle)
setCssStyle
in class UIBean
public void setAfterNotifyTopics(String afterNotifyTopics)
public void setBeforeNotifyTopics(String beforeNotifyTopics)
public void setErrorNotifyTopics(String errorNotifyTopics)
public void setValueNotifyTopics(String valueNotifyTopics)
public void setResultsLimit(String resultsLimit)
public void setTransport(String transport)
public void setPreload(String preload)
public void setKeyValue(String keyValue)
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.