Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preselect value in Struts <s:select> tag?

I have this Struts tag:

<s:select name="country.id" 
          list="countries"  
          listValue="name" 
          listKey="id"
          headerValue="Select Country"
          headerKey=""
          label="Country" />

which outputs the following HTML code:

<select name="country.id" tabindex="12" id="registration_country">
    <option value="">Select Country</option>
    <option value="1">United States</option>
    <option value="2">Afghanistan</option>
    <option value="3">Albania</option>
    <option value="4">Algeria</option>
    ...
    <option value="192">Zambia</option>
    <option value="193">Zimbabwe</option>
</select>

How do I specify that I want, for example, "Albania" to be preselected in the list?

like image 423
Dan Burzo Avatar asked Jan 26 '09 12:01

Dan Burzo


1 Answers

Use the value attribute in the s:select tag:

<s:select name="country.id" 
list="countries"  
listValue="name" 
listKey="id"
headerValue="Select Country"
headerKey=""
label="Country"
value="3" />
like image 107
Peter Hilton Avatar answered Nov 06 '22 01:11

Peter Hilton