FileDocCategorySizeDatePackage
Autocompleter.javaAPI DocExample13427Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

Autocompleter

public class Autocompleter extends ComboBox

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 FOLLOWING IS ONLY VALID WHEN AJAX IS CONFIGURED
  • href
  • errorText
  • listenTopics
  • notifyTopics
  • listenTopics
  • formId
  • formFilter
  • indicator
  • loadOnTextChange
  • loadMinimumCount
  • showDownArrow
  • searchType
'dropdownWidth' width in pixels of the drodpdown, same as autocompleter's width by default

'dropdownHeight' height in pixels of the drodown, 120 px by default

'forceValidOption' if invalid option is selected, clear autocompleter's text when focus is lost

'autoComplete', if true, make suggestions on the textbox

'formId' is the id of the html form whose fields will be seralized and passed as parameters in the request.

'formFilter' is the name of a function which will be used to filter the fields that will be seralized. This function takes as a parameter the element and returns true if the element should be included.

'listenTopics' comma separated list of topics names, that will trigger a request 'indicator' element to be shown while the request executing 'showErrorTransportText': whether errors should be displayed (on 'targets')

'loadOnTextChange' options will be reloaded everytime a character is typed on the textbox

'loadMinimumCount' minimum number of characters that will force the content to be loaded

'showDownError' show or hide the down arrow button

'searchType' how the search must be performed, options are: "startstring", "startword" and "substring"

'keyName' name of the field to which the selected key will be assigned

'iconPath' path of icon used for the dropdown

'templateCssPath' path to css file used to customize Dojo's widget

'dataFieldName' name of the field to be used as the list in the returned JSON string

'notifyTopics' comma separated list of topics names, that will be published. Three parameters are passed:

  • data: selected value when type='valuechanged'
  • type: 'before' before the request is made, 'valuechanged' when selection changes, 'load' when the request succeeds, or 'error' when it fails
  • request: request javascript object, when type='load' or type='error'
    • 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"/>

Fields Summary
public static final String
TEMPLATE
private static final String
COMPONENT_NAME
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
resultsLimit
Constructors Summary
public Autocompleter(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)

    
        
              
        super(stack, request, response);
    
Methods Summary
public voidevaluateExtraParams()

        super.evaluateExtraParams();

        if (forceValidOption != null)
            addParameter("forceValidOption", findValue(forceValidOption,
                    Boolean.class));
        if (searchType != null) {
            String type =  findString(searchType);
            if(type != null)
                addParameter("searchType", type.toUpperCase());
        }
        if (autoComplete != null)
            addParameter("autoComplete", findValue(autoComplete, Boolean.class));
        if (delay != null)
            addParameter("delay", findValue(delay, Integer.class));
        if (disabled != null)
            addParameter("disabled", findValue(disabled, Boolean.class));
        if (href != null) {
            addParameter("href", findString(href));
            addParameter("mode", "remote");
        }
        if (dropdownHeight != null)
            addParameter("dropdownHeight", findValue(dropdownHeight, Integer.class));
        if (dropdownWidth != null)
            addParameter("dropdownWidth", findValue(dropdownWidth, Integer.class));
        if (formFilter != null)
          addParameter("formFilter", findString(formFilter));
        if (formId != null)
          addParameter("formId", findString(formId));
        if (listenTopics != null)
          addParameter("listenTopics", findString(listenTopics));
        if (notifyTopics != null)
          addParameter("notifyTopics", findString(notifyTopics));
        if (indicator != null)
            addParameter("indicator", findString(indicator));
        if (loadOnTextChange != null)
            addParameter("loadOnTextChange", findValue(loadOnTextChange, Boolean.class));
        if (loadMinimumCount != null)
            addParameter("loadMinimumCount", findValue(loadMinimumCount, Integer.class));
        if (showDownArrow != null)
            addParameter("showDownArrow", findValue(showDownArrow, Boolean.class));
        else
            addParameter("showDownArrow", Boolean.TRUE);
        if(templateCssPath != null)
            addParameter("templateCssPath", findString(templateCssPath));
        if(iconPath != null)
            addParameter("iconPath", findString(iconPath));
        if(dataFieldName != null)
            addParameter("dataFieldName", findString(dataFieldName));
        if(keyName != null)
            addParameter("keyName", findString(keyName));
        else {
            keyName = name + "Key";
            addParameter("keyName", findString(keyName));
        }
        
        String keyNameExpr = "%{" + keyName + "}";
        addParameter("key", findString(keyNameExpr));
        if(resultsLimit != null)
            addParameter("searchLimit", findString(resultsLimit));
    
protected java.lang.ObjectfindListValue()

        return (list != null) ? findValue(list, Object.class) : null;
    
public java.lang.StringgetComponentName()

        return COMPONENT_NAME;
    
protected java.lang.StringgetDefaultTemplate()

        return TEMPLATE;
    
public voidsetAutoComplete(java.lang.String autoComplete)

        this.autoComplete = autoComplete;
    
public voidsetDataFieldName(java.lang.String dataFieldName)

        this.dataFieldName = dataFieldName;
    
public voidsetDelay(java.lang.String searchDelay)

        this.delay = searchDelay;
    
public voidsetDisabled(java.lang.String disabled)

        this.disabled = disabled;
    
public voidsetDropdownHeight(java.lang.String height)

        this.dropdownHeight = height;
    
public voidsetDropdownWidth(java.lang.String width)

        this.dropdownWidth = width;
    
public voidsetForceValidOption(java.lang.String forceValidOption)

        this.forceValidOption = forceValidOption;
    
public voidsetFormFilter(java.lang.String formFilter)

      this.formFilter = formFilter;
    
public voidsetFormId(java.lang.String formId)

      this.formId = formId;
    
public voidsetHref(java.lang.String href)

        this.href = href;
    
public voidsetIconPath(java.lang.String iconPath)

        this.iconPath = iconPath;
    
public voidsetIndicator(java.lang.String indicator)

        this.indicator = indicator;
    
public voidsetKeyName(java.lang.String keyName)

       this.keyName = keyName;
    
public voidsetList(java.lang.String list)

        super.setList(list);
    
public voidsetListenTopics(java.lang.String listenTopics)

      this.listenTopics = listenTopics;
    
public voidsetLoadMinimumCount(java.lang.String loadMinimumCount)

        this.loadMinimumCount = loadMinimumCount;
    
public voidsetLoadOnTextChange(java.lang.String loadOnType)

        this.loadOnTextChange = loadOnType;
    
public voidsetNotifyTopics(java.lang.String onValueChangedPublishTopic)

      this.notifyTopics = onValueChangedPublishTopic;
    
public voidsetResultsLimit(java.lang.String resultsLimit)

        this.resultsLimit = resultsLimit;
    
public voidsetSearchType(java.lang.String searchType)

        this.searchType = searchType;
    
public voidsetShowDownArrow(java.lang.String showDownArrow)

        this.showDownArrow = showDownArrow;
    
public voidsetTemplateCssPath(java.lang.String templateCssPath)

        this.templateCssPath = templateCssPath;