jqueryjspstruts2struts2-jquerystruts2-jquery-plugin

Set default value for struts 2 autocompleter


I have implemented a struts 2 autocompleter in which i have used a list of String like this -

<sj:autocompleter id="cityId"  
            cssClass="txtfield8"
                name="outlet.cityName" 
                list="cityList" 
        autoComplete="true" 
    forceValidOption="false" />

How can I set a default value for this, so that every time it loads, a default value will be shown ?


Solution

  • You should use the value attribute as suggested by @Choatech:

    value   false   false   String   "Preset the value of input element."
    

    The value specified, however, should be one of the keys listed in your cityList, not some random value.

    If the value you want to use is an header one, like Please choose a City..., then consider using the

    HTML5 placeholder attribute.