Amit Das
Amit Das

Reputation: 1107

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 ?

Upvotes: 1

Views: 701

Answers (2)

Choatech
Choatech

Reputation: 197

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" />

Upvotes: 2

Andrea Ligios
Andrea Ligios

Reputation: 50261

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.

Upvotes: 1

Related Questions