如何在Select Struts2中选择HashMap的值? [英] How to choose a value of a HashMap in select Struts2?
问题描述
我遇到了Struts2的问题.我有一个HashMap<String, Integer>
,可以在带有 select 的表单中使用,以选择名称和该名称的对应ID.
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
迭代并使用名称填充我的<select>
列表.我只需要一个ID即可选择.如何选择ID/值而不是名称/键?
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是一个HashMap
,其中<String, Integer>
或键值.
companyMap is a HashMap
, where <String, Integer>
or key, value.
companyName
是一个字符串.
<s:select label="Pick the company name"
headerKey="-1" headerValue="Select Company name"
list="companyMap.keys"
name = "companyName"
/>
推荐答案
如果列表是Map(键,值),则Map键将成为选项值"参数,而Map值将成为选项主体.
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.
但是您需要更改此规则
<s:select label="Pick the company name"
headerKey="-1" headerValue="Select Company name"
list="%{companyMap.entrySet()}"
name = "companyId"
listKey="value"
listValue="key"
/>
这篇关于如何在Select Struts2中选择HashMap的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!