org.apache.struts2.dojo.components
Class Autocompleter
java.lang.Object
org.apache.struts2.components.Component
org.apache.struts2.components.UIBean
org.apache.struts2.components.TextField
org.apache.struts2.components.ComboBox
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}" />
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 |
Constructor Summary |
Autocompleter(com.opensymphony.xwork2.util.ValueStack stack,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
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 |
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
Autocompleter
public Autocompleter(com.opensymphony.xwork2.util.ValueStack stack,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
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.