Preselect value in Struts <s:select> tag?
Asked Answered
M

2

5

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?

Midpoint answered 26/1, 2009 at 12:12 Comment(0)
A
7

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" />
Annunciation answered 27/1, 2009 at 0:21 Comment(1)
This do not work for me. Both value I have compare eventhough s:select not selecting the option. M bit new to struts. Please advice other check points. M using struts 2Pence
P
0

Try this:

headerKey="3"
Permanent answered 26/1, 2009 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.