Java 是否可以将ArrayList索引作为listkey存储到Struts 2 selectbox中?

Java 是否可以将ArrayList索引作为listkey存储到Struts 2 selectbox中?,java,jsp,struts2,arraylist,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的索引。

我有一个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中找到合适的国家并检索它。可能吗?

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

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


@user1788867:很高兴知道,这很有帮助。请不要忘记接受答案。请注意,虽然这可能无关紧要,但这是一个相当昂贵的操作,因为它将遍历列表以查找国家。在我看来,最好在提交后查找,只执行一次查找,或者在Java端创建一个索引/国家列表,等等。