struts2 combobox - pass Integer id and not String name through the form to the action
Question
my form is passing the String name of the country to the action. how can i pass the id of the object country from the combobox to the action?
this is what i have:
s:combobox label="Country" name="country" headerValue="Select" headerKey="1" list="%{countries}" listValue="name"/>
thanks.
Solution
You have missed the listKey attribute. If you change it as:
<s:combobox label="Country" name="country" headerValue="Select" headerKey="1"
list="%{countries}" listValue="name" listKey="id"/>
It will probably work.
See http://struts.apache.org/2.0.14/docs/combobox.html for all the attributes available.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow