Reputation: 9208
I have a list with 2 properties name and prefix (from SQL), where name is the language name and prefix is the language identifier composed of 2 letters.
And I want to make something like:
<select>
<option value="en">English</option>
<option value="fr">French</option>
<option value="uk">English UK</option>
</select>
I know how to do that in this way: <s:select list="#{'en':'English', 'fr':'French', 'uk':'English UK'}"/>
But how to display the results if we have a list from database, for example: <s:select list="languages.name"/>
Is is possible in Struts2 s:select tag?
Upvotes: 1
Views: 3033
Reputation: 23587
Here is how this should work.I suppose you have a ArrayList
of some object and this object have two properties name
and prefix
So In your action class you have a ArryList something like
List<LanguageObject> languageList;
which is being populated form the DB. All you need to have following entry in your JSP
<s:select name="language" list="languageList" label="Select a country" listKey="prefix"
listValue="name" />
where prefix and name are the 2 properties being defined in your object.
Upvotes: 4