diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java index 76a081aa2..bb994dd46 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java @@ -32,19 +32,56 @@ import com.opensymphony.xwork2.util.ValueStack; /** * - *
The autocomplete tag is a combobox that can autocomplete text entered on the input box. - * When used on the "simple" theme, the autocompleter can be used like the ComboBox. - * When used on the "ajax" theme, the list can be retieved from an action.
- * + *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 expects and array of arrays of length 2, where the first element is the text displayed and + * the second is the value.
+ * + *+ * + * Autocompleter that gets its list from an action: * - * - *Autocompleter that gets its list from an action:
- *<s:autocompleter name="test" href="%{jsonList}" autoComplete="false"/> - *
- **Autocompleter that uses a list:
- *<s:autocompleter name="test" list="{'apple','banana','grape','pear'}" autoComplete="false"/> - *
- * + * <sx:autocompleter name="autocompleter1" href="%{jsonList}"/> + * + * Which expects a response like: + * + * [ + * ["Text1", "Value1"], + * ["Text2", "Value2"] + * ] + * + * Or (note that now the response is a JSON object, instead of an array, and a field inside the object matches the autocompleter's name): + * + * { + * autocompleter1:[ + * ["Text1", "Value1"], + * ["Text2", "Value2"] + * ] + * } + * + * The name of the field that contains the data for the autocompleter can be specified using the "dataFieldName" attribute. + * + * Autocompleter that uses a list: + * + * <s:autocompleter name="test" list="{'apple','banana','grape','pear'}" autoComplete="false"/> + * + * Autocompleter that reloads its content everytime the text changes (and the length of the text is greater than 3): + * + * <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 + * + * Linking two autocompleters: + * + * <form id="selectForm"> + * <sx:autocompleter name="select" list="{'fruits','colors'}" valueNotifyTopics="/changed" /> + * </form> + * <sx:autocompleter href="%{jsonList}" formId="selectForm" listenTopics="/changed"/> + * + * + **/ @StrutsTag(name="autocompleter", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.AutocompleterTag", description="Renders a combobox with autocomplete and AJAX capabilities") public class Autocompleter extends ComboBox {