是否可以将ArrayList索引存储到Struts 2选择框中作为listkey?

时间:2012-11-05 15:48:26

标签: java jsp struts2 arraylist

我有一个Struts2应用程序。在jsp页面上,我使用selectbox从数据库中填充ArrayList:

<s:select name="country" list="countryList" listKey="countryId" listValue="countryName" headerKey="0" headerValue="Country" label="Select country" />

但我需要在listKey中存储而不是 id ,而是存储在ArrayList的索引中。那么我读了这个索引,在ArrayList中找到合适的国家并检索它。有可能吗?

1 个答案:

答案 0 :(得分:0)

尝试使用countryList.indexOf(country),如下所示:

<s:select name="country" list="countryList" listKey="countryList.indexOf(country)" 
                                           listValue="countryName" headerKey="0"  
                                   headerValue="Country" label="Select country"/>