我有一个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中找到合适的国家并检索它。有可能吗?
答案 0 :(得分:0)
尝试使用countryList.indexOf(country)
,如下所示:
<s:select name="country" list="countryList" listKey="countryList.indexOf(country)"
listValue="countryName" headerKey="0"
headerValue="Country" label="Select country"/>