Set default value for struts 2 autocompleter

696 views Asked by At

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 ?

2

There are 2 answers

0
Andrea Ligios On BEST ANSWER

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.

1
Choatech On

Just place your default value in the value argument.

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