问题
I ran into a problem with Struts2. I have a HashMap<String, Integer>
that I use in a form with a select to choose name and corresponding id to that name.
HashMap
iterates and populates my <select>
list with names. I only need an id to pick. How do I pick an id/value instead of a name/key?
companyMap is a HashMap
, where <String, Integer>
or key, value.
companyName
is a String.
<s:select label="Pick the company name"
headerKey="-1" headerValue="Select Company name"
list="companyMap.keys"
name = "companyName"
/>
回答1:
If the list is a Map (key, value), the Map key will become the option 'value' parameter and the Map value will become the option body.
But you need to change this rule
<s:select label="Pick the company name"
headerKey="-1" headerValue="Select Company name"
list="%{companyMap.entrySet()}"
name = "companyId"
listKey="value"
listValue="key"
/>
来源:https://stackoverflow.com/questions/39666093/how-to-choose-a-value-of-a-hashmap-in-select-struts2